Skip to content

Commit 881c245

Browse files
committed
DocCommentSpacingSniff: Fixed reporting and fixing
1 parent 7fd35ea commit 881c245

File tree

2 files changed

+19
-5
lines changed

2 files changed

+19
-5
lines changed

SlevomatCodingStandard/Sniffs/Commenting/DocCommentSpacingSniff.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,19 @@
1414
use const T_DOC_COMMENT_STRING;
1515
use const T_DOC_COMMENT_WHITESPACE;
1616
use const T_WHITESPACE;
17+
use function array_combine;
1718
use function array_diff;
1819
use function array_flip;
1920
use function array_key_exists;
2021
use function array_keys;
2122
use function array_map;
2223
use function array_merge;
2324
use function array_values;
25+
use function asort;
2426
use function count;
2527
use function explode;
2628
use function ksort;
2729
use function max;
28-
use function min;
2930
use function preg_match;
3031
use function sprintf;
3132
use function strlen;
@@ -495,16 +496,19 @@ private function checkAnnotationsGroupsOrder(
495496
}
496497

497498
if (!$incorrectAnnotationsGroupsExist) {
498-
$positionDiff = min($annotationsGroupsPositions) - min(array_keys($annotationsGroupsPositions));
499+
$positionsMappedToGroups = array_keys($annotationsGroupsPositions);
500+
$tmp = array_values($annotationsGroupsPositions);
501+
asort($tmp);
502+
$normalizedAnnotationsGroupsPositions = array_combine(array_keys($positionsMappedToGroups), array_keys($tmp));
499503

500-
foreach ($annotationsGroupsPositions as $annotationsGroupPosition => $sortedAnnotationsGroupPosition) {
501-
if ($annotationsGroupPosition === $sortedAnnotationsGroupPosition - $positionDiff) {
504+
foreach ($normalizedAnnotationsGroupsPositions as $normalizedAnnotationsGroupPosition => $sortedAnnotationsGroupPosition) {
505+
if ($normalizedAnnotationsGroupPosition === $sortedAnnotationsGroupPosition) {
502506
continue;
503507
}
504508

505509
$fix = $phpcsFile->addFixableError(
506510
'Incorrect order of annotations groups.',
507-
$annotationsGroups[$annotationsGroupPosition][0]->getStartPointer(),
511+
$annotationsGroups[$positionsMappedToGroups[$normalizedAnnotationsGroupPosition]][0]->getStartPointer(),
508512
self::CODE_INCORRECT_ORDER_OF_ANNOTATIONS_GROUPS
509513
);
510514
break;

tests/Sniffs/Commenting/data/docCommentSpacingAnnotationsGroupsNoErrors.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,4 +54,14 @@ public function anotherMethod()
5454

5555
}
5656

57+
/**
58+
* @param string $a
59+
*
60+
* @anything
61+
*/
62+
public function oneMoreMethod($a)
63+
{
64+
65+
}
66+
5767
}

0 commit comments

Comments
 (0)