@@ -165,6 +165,30 @@ protected function addFunction(FunctionNode $node, ?string $namespace = null)
165
165
}
166
166
}
167
167
168
+ /**
169
+ * @param \PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|\PhpParser\Node\Name|NullableType|UnionType|IntersectionType|null $type Type declaration
170
+ */
171
+ protected function typeToArray ($ type ): array
172
+ {
173
+ $ typeArray = [];
174
+ if ($ type !== null && ! ($ type instanceof NullableType || $ type instanceof UnionType || $ type instanceof IntersectionType)) {
175
+ $ typeAsStr = $ type ->__toString ();
176
+ if ($ type instanceof FullyQualified && 0 !== strpos ($ typeAsStr , '\\' )) {
177
+ $ typeAsStr = '\\' . $ typeAsStr ;
178
+ }
179
+ $ typeArray [] = [$ typeAsStr , false ];
180
+ } elseif ($ type instanceof NullableType) {
181
+ $ typeArray = array_merge ($ typeArray , $ this ->typeToArray ($ type ->type ));
182
+ $ typeArray [] = ['null ' , false ];
183
+ } elseif ($ type instanceof UnionType || $ type instanceof IntersectionType) {
184
+ foreach ($ type ->types as $ subType ) {
185
+ $ typeArray = array_merge ($ typeArray , $ this ->typeToArray ($ subType ));
186
+ }
187
+ }
188
+
189
+ return $ typeArray ;
190
+ }
191
+
168
192
/**
169
193
* @param \PhpParser\Node\ComplexType|\PhpParser\Node\Identifier|\PhpParser\Node\Name|NullableType|UnionType|IntersectionType|null $type Type declaration
170
194
*/
@@ -439,20 +463,14 @@ protected function manageHint($type, Reflection $object): void
439
463
440
464
$ typeArr = [];
441
465
foreach ($ type ->types as $ type ) {
442
- $ typeStr = $ this ->typeToString ($ type );
443
- $ typeArr [] = [$ typeStr , false ];
466
+ $ typeArr = array_merge ($ typeArr , $ this ->typeToArray ($ type ));
444
467
}
445
468
446
469
$ object ->setHint ($ this ->resolveHint ($ typeArr ));
447
470
} else {
448
- $ typeStr = $ this ->typeToString ($ type );
449
-
450
- if (null !== $ typeStr ) {
451
- $ typeArr = [[$ typeStr , false ]];
471
+ $ typeArr = $ this ->typeToArray ($ type );
452
472
453
- if ($ type instanceof NullableType) {
454
- $ typeArr [] = ['null ' , false ];
455
- }
473
+ if (!empty ($ typeArr )) {
456
474
$ object ->setHint ($ this ->resolveHint ($ typeArr ));
457
475
}
458
476
}
0 commit comments