Skip to content

Commit

Permalink
DocCommentSpacingSniff: Some errors were not reported and fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Sep 25, 2018
1 parent 34304e3 commit 5e87870
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,7 @@ private function checkAnnotationsGroupsOrder(
$annotationsGroupsPositions = [];

$fix = false;
$undefinedAnnotationsGroups = [];
foreach ($annotationsGroups as $annotationsGroupPosition => $annotationsGroup) {
foreach ($sortedAnnotationsGroups as $sortedAnnotationsGroupPosition => $sortedAnnotationsGroup) {
if ($equals($annotationsGroup, $sortedAnnotationsGroup)) {
Expand All @@ -482,6 +483,7 @@ private function checkAnnotationsGroupsOrder(
}

if ($undefinedAnnotationsGroup) {
$undefinedAnnotationsGroups[] = $annotationsGroupPosition;
continue 2;
}
}
Expand All @@ -496,6 +498,11 @@ private function checkAnnotationsGroupsOrder(
}

if (!$incorrectAnnotationsGroupsExist) {
foreach ($undefinedAnnotationsGroups as $undefinedAnnotationsGroupPosition) {
$annotationsGroupsPositions[$undefinedAnnotationsGroupPosition] = max($annotationsGroupsPositions) + 1;
}
ksort($annotationsGroupsPositions);

$positionsMappedToGroups = array_keys($annotationsGroupsPositions);
$tmp = array_values($annotationsGroupsPositions);
asort($tmp);
Expand All @@ -520,6 +527,10 @@ private function checkAnnotationsGroupsOrder(
continue;
}

if (!array_key_exists($annotationsGroupsPositions[$annotationsGroupPosition], $sortedAnnotationsGroups)) {
continue;
}

$sortedAnnotationsGroup = $sortedAnnotationsGroups[$annotationsGroupsPositions[$annotationsGroupPosition]];

foreach ($annotationsGroup as $annotationPosition => $annotation) {
Expand Down
5 changes: 3 additions & 2 deletions tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,13 +134,14 @@ public function testAnnotationsGroupsErrors(): void
DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP,
]);

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

self::assertSniffError($report, 20, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
self::assertSniffError($report, 34, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 46, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 44, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 49, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP);
self::assertSniffError($report, 62, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 74, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
self::assertSniffError($report, 83, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);

self::assertAllFixedInFile($report);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ public function oneMoreMethod($a, $b, $c)
}

/**
* @return bool
*
* @param int $a
*
* @return bool
*/
public function methodBeforeInvalidDocComment($a): bool
{
Expand Down

0 comments on commit 5e87870

Please sign in to comment.