@@ -154,10 +154,10 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a
154
154
$ res = [];
155
155
foreach ($ method ->getParameters () as $ i => $ param ) {
156
156
$ name = $ param ->getName ();
157
- [ $ type, $ isClass ] = self ::getParameterType ($ param );
157
+ $ type = self ::getParameterType ($ param );
158
158
if (isset ($ args [$ name ])) {
159
159
$ res [$ i ] = $ args [$ name ];
160
- if (!self ::convertType ($ res [$ i ], $ type, $ isClass )) {
160
+ if (!self ::convertType ($ res [$ i ], $ type )) {
161
161
throw new Nette \InvalidArgumentException (sprintf (
162
162
'Argument $%s passed to %s() must be %s, %s given. ' ,
163
163
$ name ,
@@ -187,9 +187,15 @@ public static function combineArgs(\ReflectionFunctionAbstract $method, array $a
187
187
/**
188
188
* Non data-loss type conversion.
189
189
*/
190
- public static function convertType (&$ val , string $ type, bool $ isClass = false ): bool
190
+ public static function convertType (&$ val , string $ type ): bool
191
191
{
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 ])) {
193
199
return $ val instanceof $ type ;
194
200
195
201
} elseif ($ type === 'callable ' ) {
@@ -240,14 +246,11 @@ public static function parseAnnotation(\Reflector $ref, string $name): ?array
240
246
}
241
247
242
248
243
- /**
244
- * @return array [string|null, bool]
245
- */
246
- public static function getParameterType (\ReflectionParameter $ param ): array
249
+ public static function getParameterType (\ReflectionParameter $ param ): string
247
250
{
248
251
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 );
251
254
}
252
255
253
256
0 commit comments