Skip to content

Commit

Permalink
ConstantSpacingSniff: Improved error message
Browse files Browse the repository at this point in the history
  • Loading branch information
kukulich committed Mar 21, 2020
1 parent 1bd1de8 commit 725678e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions SlevomatCodingStandard/Sniffs/Classes/ConstantSpacingSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,16 @@ protected function isNextMemberValid(File $phpcsFile, int $pointer): bool
return $tokens[$nextPointer]['code'] === T_CONST;
}

protected function addError(File $phpcsFile, int $pointer, int $min, int $max, int $found): bool
protected function addError(File $phpcsFile, int $pointer, int $minExpectedLines, int $maxExpectedLines, int $found): bool
{
$message = 'Expected %d to %d blank lines after constant, found %d.';
$error = sprintf($message, $min, $max, $found);
if ($minExpectedLines === $maxExpectedLines) {
$errorMessage = $minExpectedLines === 1
? 'Expected 1 blank line after constant, found %3$d.'
: 'Expected %2$d blank lines after constant, found %3$d.';
} else {
$errorMessage = 'Expected %1$d to %2$d blank lines after constant, found %3$d.';
}
$error = sprintf($errorMessage, $minExpectedLines, $maxExpectedLines, $found);

return $phpcsFile->addFixableError($error, $pointer, self::CODE_INCORRECT_COUNT_OF_BLANK_LINES_AFTER_CONSTANT);
}
Expand Down

0 comments on commit 725678e

Please sign in to comment.