Skip to content

Commit 5e87870

Browse files
committed
DocCommentSpacingSniff: Some errors were not reported and fixed
1 parent 34304e3 commit 5e87870

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed

SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,7 @@ private function checkAnnotationsGroupsOrder(
462462
$annotationsGroupsPositions = [];
463463

464464
$fix = false;
465+
$undefinedAnnotationsGroups = [];
465466
foreach ($annotationsGroups as $annotationsGroupPosition => $annotationsGroup) {
466467
foreach ($sortedAnnotationsGroups as $sortedAnnotationsGroupPosition => $sortedAnnotationsGroup) {
467468
if ($equals($annotationsGroup, $sortedAnnotationsGroup)) {
@@ -482,6 +483,7 @@ private function checkAnnotationsGroupsOrder(
482483
}
483484

484485
if ($undefinedAnnotationsGroup) {
486+
$undefinedAnnotationsGroups[] = $annotationsGroupPosition;
485487
continue 2;
486488
}
487489
}
@@ -496,6 +498,11 @@ private function checkAnnotationsGroupsOrder(
496498
}
497499

498500
if (!$incorrectAnnotationsGroupsExist) {
501+
foreach ($undefinedAnnotationsGroups as $undefinedAnnotationsGroupPosition) {
502+
$annotationsGroupsPositions[$undefinedAnnotationsGroupPosition] = max($annotationsGroupsPositions) + 1;
503+
}
504+
ksort($annotationsGroupsPositions);
505+
499506
$positionsMappedToGroups = array_keys($annotationsGroupsPositions);
500507
$tmp = array_values($annotationsGroupsPositions);
501508
asort($tmp);
@@ -520,6 +527,10 @@ private function checkAnnotationsGroupsOrder(
520527
continue;
521528
}
522529

530+
if (!array_key_exists($annotationsGroupsPositions[$annotationsGroupPosition], $sortedAnnotationsGroups)) {
531+
continue;
532+
}
533+
523534
$sortedAnnotationsGroup = $sortedAnnotationsGroups[$annotationsGroupsPositions[$annotationsGroupPosition]];
524535

525536
foreach ($annotationsGroup as $annotationPosition => $annotation) {

tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,13 +134,14 @@ public function testAnnotationsGroupsErrors(): void
134134
DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP,
135135
]);
136136

137-
self::assertSame(6, $report->getErrorCount());
137+
self::assertSame(7, $report->getErrorCount());
138138

139139
self::assertSniffError($report, 20, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
140140
self::assertSniffError($report, 34, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ANNOTATIONS_GROUPS);
141-
self::assertSniffError($report, 46, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
141+
self::assertSniffError($report, 44, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
142142
self::assertSniffError($report, 49, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP);
143143
self::assertSniffError($report, 62, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
144+
self::assertSniffError($report, 74, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
144145
self::assertSniffError($report, 83, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
145146

146147
self::assertAllFixedInFile($report);

tests/Sniffs/Commenting/data/docCommentSpacingAnnotationsGroupsErrors.fixed.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,9 +70,9 @@ public function oneMoreMethod($a, $b, $c)
7070
}
7171

7272
/**
73-
* @return bool
74-
*
7573
* @param int $a
74+
*
75+
* @return bool
7676
*/
7777
public function methodBeforeInvalidDocComment($a): bool
7878
{

0 commit comments

Comments
 (0)