Skip to content

Commit 0336c6d

Browse files
committed
close #26
1 parent 3886ddf commit 0336c6d

15 files changed

Lines changed: 69 additions & 70 deletions

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ $id = $arguments->get('id'); // 1
205205

206206
## Get argument value (typed)
207207

208-
Use method `required()` to retrieve a explicit required argument value by name or position. It returns as `CastInterface`, enabling typed access to the value. The method `optional()` can be used to retrieve an optional argument value.
208+
Use method `required()` to retrieve a explicit required argument value by name or position. It returns as `TypedInterface`, enabling type-safe access to the value. The method `optional()` can be used to retrieve an optional argument value.
209209

210210
```php
211211
$id = $arguments->required('id')->int(); // 1

composer.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"chevere/regex": "^1.0.1"
1919
},
2020
"require-dev": {
21-
"chevere/var-dump": "^2.0",
2221
"phpstan/phpstan": "^2.1",
2322
"phpunit/phpunit": "^10.5",
2423
"symplify/easy-coding-standard": "^12.3"

src/Arguments.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
namespace Chevere\Parameter;
1515

1616
use Chevere\Parameter\Interfaces\ArgumentsInterface;
17-
use Chevere\Parameter\Interfaces\CastInterface;
1817
use Chevere\Parameter\Interfaces\ParametersAccessInterface;
18+
use Chevere\Parameter\Interfaces\TypedInterface;
1919
use Chevere\Parameter\Traits\ArgumentsTrait;
2020
use Chevere\Parameter\Traits\ExceptionErrorMessageTrait;
2121
use InvalidArgumentException;
@@ -64,7 +64,7 @@ public function get(string $name): mixed
6464
return $this->arguments[$name] ?? null;
6565
}
6666

67-
public function required(string $name): CastInterface
67+
public function required(string $name): TypedInterface
6868
{
6969
if ($this->parameters()->optionalKeys()->contains($name)) {
7070
throw new InvalidArgumentException(
@@ -75,10 +75,10 @@ public function required(string $name): CastInterface
7575
);
7676
}
7777

78-
return new Cast($this->arguments[$name]);
78+
return new Typed($this->arguments[$name]);
7979
}
8080

81-
public function optional(string $name): ?CastInterface
81+
public function optional(string $name): ?TypedInterface
8282
{
8383
if ($this->parameters()->has($name)
8484
&& ! $this->parameters()->optionalKeys()->contains($name)
@@ -92,7 +92,7 @@ public function optional(string $name): ?CastInterface
9292
}
9393

9494
if ($this->has($name)) {
95-
return new Cast($this->arguments[$name]);
95+
return new Typed($this->arguments[$name]);
9696
}
9797

9898
return null;

src/Interfaces/ArgumentsInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ public function get(string $name): mixed;
5252
/**
5353
* Provides access to the required argument for the parameter `$name`.
5454
*/
55-
public function required(string $name): CastInterface;
55+
public function required(string $name): TypedInterface;
5656

5757
/**
5858
* Provides access to the optional argument for the parameter `$name`.
5959
*/
60-
public function optional(string $name): ?CastInterface;
60+
public function optional(string $name): ?TypedInterface;
6161

6262
/**
6363
* Provides access to a nested ArgumentsInterface specific to the parameter `$name`

src/Interfaces/ParameterCastInterface.php renamed to src/Interfaces/ParameterTypedInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
namespace Chevere\Parameter\Interfaces;
1515

1616
/**
17-
* Describes the component in charge of casting a parameter.
17+
* Describes the component providing type-safe access to a parameter.
1818
*/
19-
interface ParameterCastInterface
19+
interface ParameterTypedInterface
2020
{
2121
public function array(): ArrayParameterInterface;
2222

src/Interfaces/ParametersInterface.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,22 +124,22 @@ public function optionalMinimum(): int;
124124
public function get(string $name): ParameterInterface;
125125

126126
/**
127-
* Provides cast access to the required parameter by name.
127+
* Provides type-safe access to the required parameter by name.
128128
*
129129
* ```php
130130
* $parameters->required('name')->string();
131131
* ```
132132
*/
133-
public function required(string $name): ParameterCastInterface;
133+
public function required(string $name): ParameterTypedInterface;
134134

135135
/**
136-
* Provides cast access to the optional parameter by name.
136+
* Provides type-safe access to the optional parameter by name.
137137
*
138138
* ```php
139139
* $parameters->optional('name')->string();
140140
* ```
141141
*/
142-
public function optional(string $name): ParameterCastInterface;
142+
public function optional(string $name): ParameterTypedInterface;
143143

144144
/**
145145
* Return an instance with the specified $isVariadic.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
namespace Chevere\Parameter\Interfaces;
1515

1616
/**
17-
* Describes the component in charge of casting an argument.
17+
* Describes the component in charge of providing a type-safe accessor.
1818
*/
19-
interface CastInterface
19+
interface TypedInterface
2020
{
2121
public function int(): int;
2222

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
use Chevere\Parameter\Interfaces\IterableParameterInterface;
2121
use Chevere\Parameter\Interfaces\NullParameterInterface;
2222
use Chevere\Parameter\Interfaces\ObjectParameterInterface;
23-
use Chevere\Parameter\Interfaces\ParameterCastInterface;
23+
use Chevere\Parameter\Interfaces\ParameterTypedInterface;
2424
use Chevere\Parameter\Interfaces\StringParameterInterface;
2525
use Chevere\Parameter\Interfaces\UnionParameterInterface;
2626

27-
final class ParameterCast implements ParameterCastInterface
27+
final class ParameterTyped implements ParameterTypedInterface
2828
{
2929
// @phpstan-ignore-next-line
3030
public function __construct(

src/Parameters.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@
1919
use Chevere\DataStructure\Traits\MapTrait;
2020
use Chevere\DataStructure\Vector;
2121
use Chevere\Parameter\Interfaces\ArgumentsInterface;
22-
use Chevere\Parameter\Interfaces\ParameterCastInterface;
2322
use Chevere\Parameter\Interfaces\ParameterInterface;
2423
use Chevere\Parameter\Interfaces\ParametersInterface;
24+
use Chevere\Parameter\Interfaces\ParameterTypedInterface;
2525
use InvalidArgumentException;
2626
use OverflowException;
2727
use function Chevere\Message\message;
@@ -216,7 +216,7 @@ public function get(string $name): ParameterInterface
216216
return $this->map->get($name);
217217
}
218218

219-
public function required(string $name): ParameterCastInterface
219+
public function required(string $name): ParameterTypedInterface
220220
{
221221
$parameter = $this->get($name);
222222
if ($this->optionalKeys()->contains($name)) {
@@ -228,10 +228,10 @@ public function required(string $name): ParameterCastInterface
228228
);
229229
}
230230

231-
return new ParameterCast($parameter);
231+
return new ParameterTyped($parameter);
232232
}
233233

234-
public function optional(string $name): ParameterCastInterface
234+
public function optional(string $name): ParameterTypedInterface
235235
{
236236
$parameter = $this->get($name);
237237
if (! $this->optionalKeys()->contains($name)) {
@@ -243,7 +243,7 @@ public function optional(string $name): ParameterCastInterface
243243
);
244244
}
245245

246-
return new ParameterCast($parameter);
246+
return new ParameterTyped($parameter);
247247
}
248248

249249
private function remove(string ...$name): void

src/Cast.php renamed to src/Typed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313

1414
namespace Chevere\Parameter;
1515

16-
use Chevere\Parameter\Interfaces\CastInterface;
16+
use Chevere\Parameter\Interfaces\TypedInterface;
1717

18-
final class Cast implements CastInterface
18+
final class Typed implements TypedInterface
1919
{
2020
// @phpstan-ignore-next-line
2121
public function __construct(

0 commit comments

Comments
 (0)