@@ -154,10 +154,10 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a
154154 $ res = [];
155155 foreach ($ method ->getParameters () as $ i => $ param ) {
156156 $ name = $ param ->getName ();
157- [ $ type, $ isClass ] = self ::getParameterType ($ param );
157+ $ type = self ::getParameterType ($ param );
158158 if (isset ($ args [$ name ])) {
159159 $ res [$ i ] = $ args [$ name ];
160- if (!self ::convertType ($ res [$ i ], $ type, $ isClass )) {
160+ if (!self ::convertType ($ res [$ i ], $ type )) {
161161 throw new Nette \InvalidArgumentException (sprintf (
162162 'Argument $%s passed to %s() must be %s, %s given. ' ,
163163 $ name ,
@@ -187,9 +187,15 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a
187187 /**
188188 * Non data-loss type conversion.
189189 */
190- public static function convertType (&$ val , string $ type, bool $ isClass = false ): bool
190+ public static function convertType (&$ val , string $ type ): bool
191191 {
192- if ($ isClass ) {
192+ static $ builtin = [
193+ 'string ' => 1 , 'int ' => 1 , 'float ' => 1 , 'bool ' => 1 , 'array ' => 1 , 'object ' => 1 ,
194+ 'callable ' => 1 , 'iterable ' => 1 , 'void ' => 1 , 'null ' => 1 ,
195+ 'boolean ' => 1 , 'integer ' => 1 , 'double ' => 1 , 'NULL ' => 1 ,
196+ ];
197+
198+ if (empty ($ builtin [$ type ])) {
193199 return $ val instanceof $ type ;
194200
195201 } elseif ($ type === 'callable ' ) {
@@ -240,14 +246,11 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array
240246 }
241247
242248
243- /**
244- * @return array [string|null, bool]
245- */
246- public static function getParameterType (\ReflectionParameter $ param ): array
249+ public static function getParameterType (\ReflectionParameter $ param ): string
247250 {
248251 return $ param ->hasType ()
249- ? [ $ param ->getType ()->getName (), ! $ param -> getType ()-> isBuiltin ()]
250- : [ gettype ($ param ->isDefaultValueAvailable () ? $ param ->getDefaultValue () : null ), false ] ;
252+ ? $ param ->getType ()->getName ()
253+ : gettype ($ param ->isDefaultValueAvailable () ? $ param ->getDefaultValue () : null );
251254 }
252255
253256
0 commit comments