@@ -230,32 +230,25 @@ private function fixFunctionDocComment($content, Tokens $tokens, $functionIndex,
230
230
231
231
/**
232
232
* @param string $content
233
- * @param int $docCommentIndex
233
+ * @param int $index Index of the DocComment token
234
234
*
235
235
* @return string
236
236
*/
237
- private function fixPropertyDocComment ($ content , Tokens $ tokens , $ docCommentIndex , array $ shortNames )
237
+ private function fixPropertyDocComment ($ content , Tokens $ tokens , $ index , array $ shortNames )
238
238
{
239
239
$ docBlock = new DocBlock ($ content );
240
240
241
- $ index = $ tokens ->getNextMeaningfulToken ($ docCommentIndex );
242
-
243
- $ kindsBeforeProperty = [T_STATIC , T_PRIVATE , T_PROTECTED , T_PUBLIC ];
244
-
245
- if (!$ tokens [$ index ]->isGivenKind ($ kindsBeforeProperty )) {
246
- return $ content ;
247
- }
248
-
249
241
do {
250
242
$ index = $ tokens ->getNextMeaningfulToken ($ index );
243
+ } while ($ tokens [$ index ]->isGivenKind ([T_STATIC , T_PRIVATE , T_PROTECTED , T_PUBLIC ]));
251
244
252
- $ propertyTypeInfo = $ this ->parseTypeHint ($ tokens , $ index );
253
- foreach ( $ docBlock -> getAnnotationsOfType ( ' var ' ) as $ annotation ) {
254
- if ( $ this -> annotationIsSuperfluous ( $ annotation , $ propertyTypeInfo , $ shortNames ) ) {
255
- $ annotation -> remove ();
256
- }
245
+ $ propertyTypeInfo = $ this ->getPropertyTypeInfo ($ tokens , $ index );
246
+
247
+ foreach ( $ docBlock -> getAnnotationsOfType ( ' var ' ) as $ annotation ) {
248
+ if ( $ this -> annotationIsSuperfluous ( $ annotation , $ propertyTypeInfo , $ shortNames )) {
249
+ $ annotation -> remove ();
257
250
}
258
- } while ( $ tokens [ $ index ]-> isGivenKind ( $ kindsBeforeProperty ));
251
+ }
259
252
260
253
return $ docBlock ->getContent ();
261
254
}
@@ -318,6 +311,23 @@ private function getReturnTypeInfo(Tokens $tokens, $closingParenthesisIndex)
318
311
];
319
312
}
320
313
314
+ /**
315
+ * @param int $index The index of the first token of the type hint
316
+ *
317
+ * @return array
318
+ */
319
+ private function getPropertyTypeInfo (Tokens $ tokens , $ index )
320
+ {
321
+ if ($ tokens [$ index ]->isGivenKind (T_VARIABLE )) {
322
+ return [
323
+ 'type ' => null ,
324
+ 'allows_null ' => true ,
325
+ ];
326
+ }
327
+
328
+ return $ this ->parseTypeHint ($ tokens , $ index );
329
+ }
330
+
321
331
/**
322
332
* @param int $index The index of the first token of the type hint
323
333
*
0 commit comments