From 7e559ae59bf6f8fe258619766ed1d0ede3dedff5 Mon Sep 17 00:00:00 2001 From: Rodolfo Berrios <20590102+rodber@users.noreply.github.com> Date: Thu, 8 Feb 2024 12:44:27 -0300 Subject: [PATCH] iterable stuff --- src/Interfaces/TypeInterface.php | 2 ++ src/functions.php | 10 ++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Interfaces/TypeInterface.php b/src/Interfaces/TypeInterface.php index 73fc055..e292143 100644 --- a/src/Interfaces/TypeInterface.php +++ b/src/Interfaces/TypeInterface.php @@ -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; @@ -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, diff --git a/src/functions.php b/src/functions.php index 883098a..8ef0f3c 100644 --- a/src/functions.php +++ b/src/functions.php @@ -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); @@ -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 {