@@ -70,7 +70,23 @@ private function isTokenBeforeClosingCommentTagValid(string $type): bool
70
70
private function validateCommentBlockExists (File $ phpcsFile , int $ previousCommentClosePtr , int $ stackPtr ): bool
71
71
{
72
72
$ tokens = $ phpcsFile ->getTokens ();
73
+ $ attributeFlag = false ;
73
74
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
+
74
90
if (!$ this ->isTokenBeforeClosingCommentTagValid ($ tokens [$ tempPtr ]['type ' ])) {
75
91
return false ;
76
92
}
@@ -228,15 +244,15 @@ private function validateParameterAnnotationForArgumentExists(
228
244
$ phpcsFile ->addError (
229
245
'{@inheritdoc} does not import parameter annotation ' ,
230
246
$ stackPtr ,
231
- 'MethodArguments '
247
+ 'InheritDoc '
232
248
);
233
249
} elseif ($ this ->validateCommentBlockExists ($ phpcsFile , $ previousCommentClosePtr , $ stackPtr )
234
250
&& !$ inheritdocAnnotationWithoutBracesExists
235
251
) {
236
252
$ phpcsFile ->addError (
237
253
'Missing @param for argument in method annotation ' ,
238
254
$ stackPtr ,
239
- 'MethodArguments '
255
+ 'ParamMissing '
240
256
);
241
257
}
242
258
}
@@ -260,13 +276,13 @@ private function validateCommentBlockDoesnotHaveExtraParameterAnnotation(
260
276
$ phpcsFile ->addError (
261
277
'Extra @param found in method annotation ' ,
262
278
$ stackPtr ,
263
- 'MethodArguments '
279
+ 'ExtraParam '
264
280
);
265
281
} elseif ($ argumentsCount > 0 && $ argumentsCount != $ parametersCount && $ parametersCount != 0 ) {
266
282
$ phpcsFile ->addError (
267
283
'@param is not found for one or more params in method annotation ' ,
268
284
$ stackPtr ,
269
- 'MethodArguments '
285
+ 'ParamMissing '
270
286
);
271
287
}
272
288
}
@@ -290,7 +306,7 @@ private function validateArgumentNameInParameterAnnotationExists(
290
306
$ parameterNames = $ this ->getMethodParameters ($ paramDefinitions );
291
307
if (!in_array ($ methodArguments [$ ptr ], $ parameterNames )) {
292
308
$ error = $ methodArguments [$ ptr ] . ' parameter is missing in method annotation ' ;
293
- $ phpcsFile ->addError ($ error , $ stackPtr , 'MethodArguments ' );
309
+ $ phpcsFile ->addError ($ error , $ stackPtr , 'ArgumentMissing ' );
294
310
}
295
311
}
296
312
@@ -314,7 +330,7 @@ private function validateParameterPresentInMethodSignature(
314
330
$ phpcsFile ->addError (
315
331
$ paramDefinitionsArguments . ' parameter is missing in method arguments signature ' ,
316
332
$ paramPointers [$ ptr ],
317
- 'MethodArguments '
333
+ 'ArgumentMissing '
318
334
);
319
335
}
320
336
}
@@ -343,7 +359,7 @@ private function validateParameterOrderIsCorrect(
343
359
$ phpcsFile ->addError (
344
360
$ methodArguments [$ ptr ] . ' parameter is not in order ' ,
345
361
$ paramPointers [$ ptr ],
346
- 'MethodArguments '
362
+ 'ParamOrder '
347
363
);
348
364
}
349
365
}
@@ -386,7 +402,7 @@ private function validateDuplicateAnnotationDoesnotExists(
386
402
$ phpcsFile ->addError (
387
403
$ value . ' duplicate found in method annotation ' ,
388
404
$ stackPtr ,
389
- 'MethodArguments '
405
+ 'DuplicateParam '
390
406
);
391
407
}
392
408
}
@@ -413,15 +429,15 @@ private function validateParameterAnnotationFormatIsCorrect(
413
429
$ phpcsFile ->addError (
414
430
'Missing both type and parameter ' ,
415
431
$ paramPointers [$ ptr ],
416
- 'MethodArguments '
432
+ 'Malformed '
417
433
);
418
434
break ;
419
435
case 1 :
420
436
if (preg_match ('/^\$.*/ ' , $ paramDefinitions [0 ])) {
421
437
$ phpcsFile ->addError (
422
438
'Type is not specified ' ,
423
439
$ paramPointers [$ ptr ],
424
- 'MethodArguments '
440
+ 'NoTypeSpecified '
425
441
);
426
442
}
427
443
break ;
@@ -430,7 +446,7 @@ private function validateParameterAnnotationFormatIsCorrect(
430
446
$ phpcsFile ->addError (
431
447
$ paramDefinitions [0 ] . ' is not a valid PHP type ' ,
432
448
$ paramPointers [$ ptr ],
433
- 'MethodArguments '
449
+ 'NotValidType '
434
450
);
435
451
}
436
452
$ this ->validateParameterPresentInMethodSignature (
@@ -446,13 +462,13 @@ private function validateParameterAnnotationFormatIsCorrect(
446
462
$ phpcsFile ->addError (
447
463
'Type is not specified ' ,
448
464
$ paramPointers [$ ptr ],
449
- 'MethodArguments '
465
+ 'NoTypeSpecified '
450
466
);
451
467
if ($ this ->isInvalidType ($ paramDefinitions [0 ])) {
452
468
$ phpcsFile ->addError (
453
469
$ paramDefinitions [0 ] . ' is not a valid PHP type ' ,
454
470
$ paramPointers [$ ptr ],
455
- 'MethodArguments '
471
+ 'NotValidType '
456
472
);
457
473
}
458
474
}
@@ -552,7 +568,7 @@ public function process(File $phpcsFile, $stackPtr)
552
568
$ previousCommentClosePtr = $ phpcsFile ->findPrevious (T_DOC_COMMENT_CLOSE_TAG , $ stackPtr - 1 , 0 );
553
569
if ($ previousCommentClosePtr && $ previousCommentOpenPtr ) {
554
570
if (!$ this ->validateCommentBlockExists ($ phpcsFile , $ previousCommentClosePtr , $ stackPtr )) {
555
- $ phpcsFile ->addError ('Comment block is missing ' , $ stackPtr , 'MethodArguments ' );
571
+ $ phpcsFile ->addError ('Comment block is missing ' , $ stackPtr , 'NoCommentBlock ' );
556
572
return ;
557
573
}
558
574
} else {
@@ -636,7 +652,7 @@ private function validateFormattingConsistency(
636
652
$ phpcsFile ->addError (
637
653
'Method arguments visual alignment must be consistent ' ,
638
654
$ paramPointers [0 ],
639
- 'MethodArguments '
655
+ 'VisualAlignment '
640
656
);
641
657
}
642
658
}
0 commit comments