@@ -39,26 +39,36 @@ public static function getTypeHint(\ReflectionFunctionAbstract $r, \ReflectionPa
39
39
if (!$ type ) {
40
40
return null ;
41
41
}
42
- if (!\is_string ($ type )) {
43
- $ name = $ type instanceof \ReflectionNamedType ? $ type ->getName () : $ type ->__toString ();
44
42
45
- if ($ type ->isBuiltin ()) {
46
- return $ noBuiltin ? null : $ name ;
43
+ $ types = [];
44
+
45
+ foreach ($ type instanceof \ReflectionUnionType ? $ type ->getTypes () : [$ type ] as $ type ) {
46
+ $ name = $ type instanceof \ReflectionNamedType ? $ type ->getName () : (string ) $ type ;
47
+
48
+ if (!\is_string ($ type ) && $ type ->isBuiltin ()) {
49
+ if (!$ noBuiltin ) {
50
+ $ types [] = $ name ;
51
+ }
52
+ continue ;
47
53
}
48
- }
49
- $ lcName = strtolower ($ name );
50
- $ prefix = $ noBuiltin ? '' : '\\' ;
51
54
52
- if ('self ' !== $ lcName && 'parent ' !== $ lcName ) {
53
- return $ prefix .$ name ;
54
- }
55
- if (!$ r instanceof \ReflectionMethod) {
56
- return null ;
57
- }
58
- if ('self ' === $ lcName ) {
59
- return $ prefix .$ r ->getDeclaringClass ()->name ;
55
+ $ lcName = strtolower ($ name );
56
+ $ prefix = $ noBuiltin ? '' : '\\' ;
57
+
58
+ if ('self ' !== $ lcName && 'parent ' !== $ lcName ) {
59
+ $ types [] = '' !== $ prefix ? $ prefix .$ name : $ name ;
60
+ continue ;
61
+ }
62
+ if (!$ r instanceof \ReflectionMethod) {
63
+ continue ;
64
+ }
65
+ if ('self ' === $ lcName ) {
66
+ $ types [] = $ prefix .$ r ->getDeclaringClass ()->name ;
67
+ } else {
68
+ $ types [] = ($ parent = $ r ->getDeclaringClass ()->getParentClass ()) ? $ prefix .$ parent ->name : null ;
69
+ }
60
70
}
61
71
62
- return ( $ parent = $ r -> getDeclaringClass ()-> getParentClass ()) ? $ prefix . $ parent -> name : null ;
72
+ return $ types ? implode ( ' | ' , $ types ) : null ;
63
73
}
64
74
}
0 commit comments