@@ -64,36 +64,38 @@ public function resolve(mixed $subject, ?TypeContext $typeContext = null): Type
64
64
throw new UnsupportedException (\sprintf ('Expected subject to be a "ReflectionProperty", a "ReflectionParameter" or a "ReflectionFunctionAbstract", "%s" given. ' , get_debug_type ($ subject )), $ subject );
65
65
}
66
66
67
- $ docComment = match (true ) {
68
- $ subject instanceof \ReflectionProperty => $ subject ->isPromoted () ? $ subject ->getDeclaringClass ()?->getConstructor()?->getDocComment() : $ subject ->getDocComment (),
69
- $ subject instanceof \ReflectionParameter => $ subject ->getDeclaringFunction ()->getDocComment (),
70
- $ subject instanceof \ReflectionFunctionAbstract => $ subject ->getDocComment (),
67
+ $ typeContext ??= $ this ->typeContextFactory ->createFromReflection ($ subject );
68
+
69
+ $ docComments = match (true ) {
70
+ $ subject instanceof \ReflectionProperty => $ subject ->isPromoted ()
71
+ ? ['@var ' => $ subject ->getDocComment (), '@param ' => $ subject ->getDeclaringClass ()?->getConstructor()?->getDocComment()]
72
+ : ['@var ' => $ subject ->getDocComment ()],
73
+ $ subject instanceof \ReflectionParameter => ['@param ' => $ subject ->getDeclaringFunction ()->getDocComment ()],
74
+ $ subject instanceof \ReflectionFunctionAbstract => ['@return ' => $ subject ->getDocComment ()],
71
75
};
72
76
73
- if (!$ docComment ) {
74
- return $ this ->reflectionTypeResolver ->resolve ($ subject );
75
- }
77
+ foreach ($ docComments as $ tagName => $ docComment ) {
78
+ if (!$ docComment ) {
79
+ continue ;
80
+ }
76
81
77
- $ typeContext ??= $ this ->typeContextFactory ->createFromReflection ($ subject );
82
+ $ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ docComment ));
83
+ $ docNode = $ this ->phpDocParser ->parse ($ tokens );
78
84
79
- $ tagName = match (true ) {
80
- $ subject instanceof \ReflectionProperty => $ subject ->isPromoted () ? '@param ' : '@var ' ,
81
- $ subject instanceof \ReflectionParameter => '@param ' ,
82
- $ subject instanceof \ReflectionFunctionAbstract => '@return ' ,
83
- };
85
+ foreach ($ docNode ->getTagsByName ($ tagName ) as $ tag ) {
86
+ $ tagValue = $ tag ->value ;
84
87
85
- $ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ docComment ));
86
- $ docNode = $ this ->phpDocParser ->parse ($ tokens );
88
+ if ('@var ' === $ tagName && $ tagValue instanceof VarTagValueNode) {
89
+ return $ this ->stringTypeResolver ->resolve ((string ) $ tagValue , $ typeContext );
90
+ }
87
91
88
- foreach ($ docNode ->getTagsByName ($ tagName ) as $ tag ) {
89
- $ tagValue = $ tag ->value ;
92
+ if ('@param ' === $ tagName && $ tagValue instanceof ParamTagValueNode && '$ ' .$ subject ->getName () === $ tagValue ->parameterName ) {
93
+ return $ this ->stringTypeResolver ->resolve ((string ) $ tagValue , $ typeContext );
94
+ }
90
95
91
- if (
92
- $ tagValue instanceof VarTagValueNode
93
- || $ tagValue instanceof ParamTagValueNode && $ tagName && '$ ' .$ subject ->getName () === $ tagValue ->parameterName
94
- || $ tagValue instanceof ReturnTagValueNode
95
- ) {
96
- return $ this ->stringTypeResolver ->resolve ((string ) $ tagValue , $ typeContext );
96
+ if ('@return ' === $ tagName && $ tagValue instanceof ReturnTagValueNode) {
97
+ return $ this ->stringTypeResolver ->resolve ((string ) $ tagValue , $ typeContext );
98
+ }
97
99
}
98
100
}
99
101
0 commit comments