Skip to content

Commit

Permalink
iterable stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
rodber committed Feb 8, 2024
1 parent 386406f commit 7e559ae
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/Interfaces/TypeInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
use Chevere\Parameter\BoolParameter;
use Chevere\Parameter\FloatParameter;
use Chevere\Parameter\IntParameter;
use Chevere\Parameter\IterableParameter;
use Chevere\Parameter\MixedParameter;
use Chevere\Parameter\NullParameter;
use Chevere\Parameter\ObjectParameter;
Expand Down Expand Up @@ -102,6 +103,7 @@ interface TypeInterface
'bool' => BoolParameter::class,
'float' => FloatParameter::class,
'int' => IntParameter::class,
'iterable' => IterableParameter::class,
'string' => StringParameter::class,
'object' => ObjectParameter::class,
'null' => NullParameter::class,
Expand Down
10 changes: 8 additions & 2 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,12 @@ function toParameter(string $type): ParameterInterface
$class = TypeInterface::TYPE_TO_PARAMETER['object'];
$className = $type;
}
$parameter = new $class();
$arguments = [];
if ($class === IterableParameter::class) {
$parameter = iterable(mixed());
} else {
$parameter = new $class(...$arguments);
}
if (isset($className)) {
// @phpstan-ignore-next-line
$parameter = $parameter->withClassName($className);
Expand Down Expand Up @@ -252,7 +257,8 @@ function reflectionToParameters(ReflectionFunction|ReflectionMethod $reflection)
$push = reflectedParameterAttribute($reflectionParameter);
$push = $push->parameter();
} catch (LogicException) {
$push = mixed();
$reflectType = new ReflectionParameterTyped($reflectionParameter);
$push = $reflectType->parameter();
}
if ($reflectionParameter->isDefaultValueAvailable()) {
try {
Expand Down

0 comments on commit 7e559ae

Please sign in to comment.