Skip to content

Commit

Permalink
Improve violation message for ClassStructureSniff
Browse files Browse the repository at this point in the history
  • Loading branch information
grongor authored and kukulich committed Feb 5, 2020
1 parent 672452c commit 3f28b83
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions SlevomatCodingStandard/Sniffs/Classes/ClassStructureSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
use SlevomatCodingStandard\Helpers\SniffSettingsHelper;
use SlevomatCodingStandard\Helpers\TokenHelper;
use function array_diff;
use function array_filter;
use function array_flip;
use function array_key_exists;
use function array_keys;
use function array_merge;
use function array_values;
use function assert;
use function count;
use function implode;
use function in_array;
use function preg_replace;
use function preg_split;
Expand Down Expand Up @@ -132,8 +133,19 @@ public function process(File $phpcsFile, $pointer): int
continue;
}

$expectedGroups = array_filter(
$groupsOrder,
static function (int $order) use ($groupsOrder, $expectedGroup): bool {
return $order >= $groupsOrder[$expectedGroup];
}
);
$fix = $phpcsFile->addFixableError(
sprintf('The placement of "%s" group is invalid.', $group),
sprintf(
'The placement of "%s" group is invalid. Last group was "%s" and one of these is expected after it: %s',
$group,
$expectedGroup,
implode(', ', array_keys($expectedGroups))
),
$groupFirstMemberPointer,
self::CODE_INCORRECT_GROUP_ORDER
);
Expand Down

0 comments on commit 3f28b83

Please sign in to comment.