@@ -183,9 +183,7 @@ private function getDocBlockFromConstructor(string $class, string $property): ?P
183
183
return null ;
184
184
}
185
185
186
- $ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ rawDocNode ));
187
- $ phpDocNode = $ this ->phpDocParser ->parse ($ tokens );
188
- $ tokens ->consumeTokenType (Lexer::TOKEN_END );
186
+ $ phpDocNode = $ this ->getPhpDocNode ($ rawDocNode );
189
187
190
188
return $ this ->filterDocBlockParams ($ phpDocNode , $ property );
191
189
}
@@ -239,24 +237,27 @@ private function getDocBlockFromProperty(string $class, string $property): ?arra
239
237
return null ;
240
238
}
241
239
240
+ // Type can be inside property docblock as `@var`
241
+ $ rawDocNode = $ reflectionProperty ->getDocComment ();
242
+ $ phpDocNode = $ rawDocNode ? $ this ->getPhpDocNode ($ rawDocNode ) : null ;
242
243
$ source = self ::PROPERTY ;
243
244
244
- if ($ reflectionProperty ->isPromoted ()) {
245
+ if (!$ phpDocNode ?->getTagsByName('@var ' )) {
246
+ $ phpDocNode = null ;
247
+ }
248
+
249
+ // or in the constructor as `@param` for promoted properties
250
+ if (!$ phpDocNode && $ reflectionProperty ->isPromoted ()) {
245
251
$ constructor = new \ReflectionMethod ($ class , '__construct ' );
246
252
$ rawDocNode = $ constructor ->getDocComment ();
253
+ $ phpDocNode = $ rawDocNode ? $ this ->getPhpDocNode ($ rawDocNode ) : null ;
247
254
$ source = self ::MUTATOR ;
248
- } else {
249
- $ rawDocNode = $ reflectionProperty ->getDocComment ();
250
255
}
251
256
252
- if (!$ rawDocNode ) {
257
+ if (!$ phpDocNode ) {
253
258
return null ;
254
259
}
255
260
256
- $ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ rawDocNode ));
257
- $ phpDocNode = $ this ->phpDocParser ->parse ($ tokens );
258
- $ tokens ->consumeTokenType (Lexer::TOKEN_END );
259
-
260
261
return [$ phpDocNode , $ source , $ reflectionProperty ->class ];
261
262
}
262
263
@@ -296,10 +297,17 @@ private function getDocBlockFromMethod(string $class, string $ucFirstProperty, i
296
297
return null ;
297
298
}
298
299
300
+ $ phpDocNode = $ this ->getPhpDocNode ($ rawDocNode );
301
+
302
+ return [$ phpDocNode , $ prefix , $ reflectionMethod ->class ];
303
+ }
304
+
305
+ private function getPhpDocNode (string $ rawDocNode ): PhpDocNode
306
+ {
299
307
$ tokens = new TokenIterator ($ this ->lexer ->tokenize ($ rawDocNode ));
300
308
$ phpDocNode = $ this ->phpDocParser ->parse ($ tokens );
301
309
$ tokens ->consumeTokenType (Lexer::TOKEN_END );
302
310
303
- return [ $ phpDocNode, $ prefix , $ reflectionMethod -> class ] ;
311
+ return $ phpDocNode ;
304
312
}
305
313
}
0 commit comments