@@ -70,7 +70,23 @@ private function isTokenBeforeClosingCommentTagValid(string $type): bool
7070 private function validateCommentBlockExists (File $ phpcsFile , int $ previousCommentClosePtr , int $ stackPtr ): bool
7171 {
7272 $ tokens = $ phpcsFile ->getTokens ();
73+ $ attributeFlag = false ;
7374 for ($ tempPtr = $ previousCommentClosePtr + 1 ; $ tempPtr < $ stackPtr ; $ tempPtr ++) {
75+ $ tokenCode = $ tokens [$ tempPtr ]['code ' ];
76+
77+ // Ignore attributes e.g. #[\ReturnTypeWillChange]
78+ if ($ tokenCode === T_ATTRIBUTE_END ) {
79+ $ attributeFlag = false ;
80+ continue ;
81+ }
82+ if ($ attributeFlag ) {
83+ continue ;
84+ }
85+ if ($ tokenCode === T_ATTRIBUTE ) {
86+ $ attributeFlag = true ;
87+ continue ;
88+ }
89+
7490 if (!$ this ->isTokenBeforeClosingCommentTagValid ($ tokens [$ tempPtr ]['type ' ])) {
7591 return false ;
7692 }
@@ -228,15 +244,15 @@ private function validateParameterAnnotationForArgumentExists(
228244 $ phpcsFile ->addError (
229245 '{@inheritdoc} does not import parameter annotation ' ,
230246 $ stackPtr ,
231- 'MethodArguments '
247+ 'InheritDoc '
232248 );
233249 } elseif ($ this ->validateCommentBlockExists ($ phpcsFile , $ previousCommentClosePtr , $ stackPtr )
234250 && !$ inheritdocAnnotationWithoutBracesExists
235251 ) {
236252 $ phpcsFile ->addError (
237253 'Missing @param for argument in method annotation ' ,
238254 $ stackPtr ,
239- 'MethodArguments '
255+ 'ParamMissing '
240256 );
241257 }
242258 }
@@ -260,13 +276,13 @@ private function validateCommentBlockDoesnotHaveExtraParameterAnnotation(
260276 $ phpcsFile ->addError (
261277 'Extra @param found in method annotation ' ,
262278 $ stackPtr ,
263- 'MethodArguments '
279+ 'ExtraParam '
264280 );
265281 } elseif ($ argumentsCount > 0 && $ argumentsCount != $ parametersCount && $ parametersCount != 0 ) {
266282 $ phpcsFile ->addError (
267283 '@param is not found for one or more params in method annotation ' ,
268284 $ stackPtr ,
269- 'MethodArguments '
285+ 'ParamMissing '
270286 );
271287 }
272288 }
@@ -290,7 +306,7 @@ private function validateArgumentNameInParameterAnnotationExists(
290306 $ parameterNames = $ this ->getMethodParameters ($ paramDefinitions );
291307 if (!in_array ($ methodArguments [$ ptr ], $ parameterNames )) {
292308 $ error = $ methodArguments [$ ptr ] . ' parameter is missing in method annotation ' ;
293- $ phpcsFile ->addError ($ error , $ stackPtr , 'MethodArguments ' );
309+ $ phpcsFile ->addError ($ error , $ stackPtr , 'ArgumentMissing ' );
294310 }
295311 }
296312
@@ -314,7 +330,7 @@ private function validateParameterPresentInMethodSignature(
314330 $ phpcsFile ->addError (
315331 $ paramDefinitionsArguments . ' parameter is missing in method arguments signature ' ,
316332 $ paramPointers [$ ptr ],
317- 'MethodArguments '
333+ 'ArgumentMissing '
318334 );
319335 }
320336 }
@@ -343,7 +359,7 @@ private function validateParameterOrderIsCorrect(
343359 $ phpcsFile ->addError (
344360 $ methodArguments [$ ptr ] . ' parameter is not in order ' ,
345361 $ paramPointers [$ ptr ],
346- 'MethodArguments '
362+ 'ParamOrder '
347363 );
348364 }
349365 }
@@ -386,7 +402,7 @@ private function validateDuplicateAnnotationDoesnotExists(
386402 $ phpcsFile ->addError (
387403 $ value . ' duplicate found in method annotation ' ,
388404 $ stackPtr ,
389- 'MethodArguments '
405+ 'DuplicateParam '
390406 );
391407 }
392408 }
@@ -413,15 +429,15 @@ private function validateParameterAnnotationFormatIsCorrect(
413429 $ phpcsFile ->addError (
414430 'Missing both type and parameter ' ,
415431 $ paramPointers [$ ptr ],
416- 'MethodArguments '
432+ 'Malformed '
417433 );
418434 break ;
419435 case 1 :
420436 if (preg_match ('/^\$.*/ ' , $ paramDefinitions [0 ])) {
421437 $ phpcsFile ->addError (
422438 'Type is not specified ' ,
423439 $ paramPointers [$ ptr ],
424- 'MethodArguments '
440+ 'NoTypeSpecified '
425441 );
426442 }
427443 break ;
@@ -430,7 +446,7 @@ private function validateParameterAnnotationFormatIsCorrect(
430446 $ phpcsFile ->addError (
431447 $ paramDefinitions [0 ] . ' is not a valid PHP type ' ,
432448 $ paramPointers [$ ptr ],
433- 'MethodArguments '
449+ 'NotValidType '
434450 );
435451 }
436452 $ this ->validateParameterPresentInMethodSignature (
@@ -446,13 +462,13 @@ private function validateParameterAnnotationFormatIsCorrect(
446462 $ phpcsFile ->addError (
447463 'Type is not specified ' ,
448464 $ paramPointers [$ ptr ],
449- 'MethodArguments '
465+ 'NoTypeSpecified '
450466 );
451467 if ($ this ->isInvalidType ($ paramDefinitions [0 ])) {
452468 $ phpcsFile ->addError (
453469 $ paramDefinitions [0 ] . ' is not a valid PHP type ' ,
454470 $ paramPointers [$ ptr ],
455- 'MethodArguments '
471+ 'NotValidType '
456472 );
457473 }
458474 }
@@ -552,7 +568,7 @@ public function process(File $phpcsFile, $stackPtr)
552568 $ previousCommentClosePtr = $ phpcsFile ->findPrevious (T_DOC_COMMENT_CLOSE_TAG , $ stackPtr - 1 , 0 );
553569 if ($ previousCommentClosePtr && $ previousCommentOpenPtr ) {
554570 if (!$ this ->validateCommentBlockExists ($ phpcsFile , $ previousCommentClosePtr , $ stackPtr )) {
555- $ phpcsFile ->addError ('Comment block is missing ' , $ stackPtr , 'MethodArguments ' );
571+ $ phpcsFile ->addError ('Comment block is missing ' , $ stackPtr , 'NoCommentBlock ' );
556572 return ;
557573 }
558574 } else {
@@ -636,7 +652,7 @@ private function validateFormattingConsistency(
636652 $ phpcsFile ->addError (
637653 'Method arguments visual alignment must be consistent ' ,
638654 $ paramPointers [0 ],
639- 'MethodArguments '
655+ 'VisualAlignment '
640656 );
641657 }
642658 }
0 commit comments