Skip to content

Commit ae2e465

Browse files
committed
DocCommentSpacingSniff: Some errors were not reported
1 parent a96ac00 commit ae2e465

File tree

4 files changed

+31
-6
lines changed

4 files changed

+31
-6
lines changed

SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use const T_DOC_COMMENT_STRING;
1515
use const T_DOC_COMMENT_WHITESPACE;
1616
use const T_WHITESPACE;
17-
use function array_combine;
1817
use function array_diff;
1918
use function array_flip;
2019
use function array_key_exists;
@@ -26,8 +25,8 @@
2625
use function explode;
2726
use function ksort;
2827
use function max;
28+
use function min;
2929
use function preg_match;
30-
use function range;
3130
use function sprintf;
3231
use function strlen;
3332
use function strpos;
@@ -494,10 +493,10 @@ private function checkAnnotationsGroupsOrder(
494493
}
495494

496495
if (!$incorrectAnnotationsGroupsExist) {
497-
$recalculatedAnnotationsGroupsPositions = array_combine(array_keys($annotationsGroupsPositions), range(0, count($annotationsGroupsPositions) - 1));
496+
$positionDiff = min($annotationsGroupsPositions) - min(array_keys($annotationsGroupsPositions));
498497

499-
foreach ($recalculatedAnnotationsGroupsPositions as $annotationsGroupPosition => $sortedAnnotationsGroupPosition) {
500-
if ($annotationsGroupPosition === $sortedAnnotationsGroupPosition) {
498+
foreach ($annotationsGroupsPositions as $annotationsGroupPosition => $sortedAnnotationsGroupPosition) {
499+
if ($annotationsGroupPosition === $sortedAnnotationsGroupPosition - $positionDiff) {
501500
continue;
502501
}
503502

tests/Sniffs/Commenting/DocCommentSpacingSniffTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public function testAnnotationsGroupsErrors(): void
119119
$report = self::checkFile(__DIR__ . '/data/docCommentSpacingAnnotationsGroupsErrors.php', [
120120
'linesCountBetweenAnnotationsGroups' => 1,
121121
'annotationsGroups' => [
122+
'@dataProvider',
122123
'@param',
123124
'@X\\Boo,@X\\,@XX',
124125
'@throws',
@@ -133,12 +134,13 @@ public function testAnnotationsGroupsErrors(): void
133134
DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP,
134135
]);
135136

136-
self::assertSame(4, $report->getErrorCount());
137+
self::assertSame(5, $report->getErrorCount());
137138

138139
self::assertSniffError($report, 20, DocCommentSpacingSniff::CODE_INCORRECT_ANNOTATIONS_GROUP);
139140
self::assertSniffError($report, 34, DocCommentSpacingSniff::CODE_INCORRECT_LINES_COUNT_BETWEEN_ANNOTATIONS_GROUPS);
140141
self::assertSniffError($report, 46, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
141142
self::assertSniffError($report, 49, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_IN_GROUP);
143+
self::assertSniffError($report, 62, DocCommentSpacingSniff::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS);
142144

143145
self::assertAllFixedInFile($report);
144146
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,16 @@ public function anotherMethod()
5757

5858
}
5959

60+
/**
61+
* @dataProvider oneMoreMethodData
62+
*
63+
* @param int $a
64+
* @param int|null $b
65+
* @param string $c
66+
*/
67+
public function oneMoreMethod($a, $b, $c)
68+
{
69+
70+
}
71+
6072
}

tests/Sniffs/Commenting/data/docCommentSpacingAnnotationsGroupsErrors.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,4 +58,16 @@ public function anotherMethod()
5858

5959
}
6060

61+
/**
62+
* @param int $a
63+
* @param int|null $b
64+
* @param string $c
65+
*
66+
* @dataProvider oneMoreMethodData
67+
*/
68+
public function oneMoreMethod($a, $b, $c)
69+
{
70+
71+
}
72+
6173
}

0 commit comments

Comments
 (0)