Skip to content

Commit

Permalink
Squiz/ClosingDeclarationComment: use $data rather than composing th…
Browse files Browse the repository at this point in the history
…e error message in parts.
  • Loading branch information
jrfnl committed Apr 14, 2017
1 parent 46983c7 commit b36d20b
Showing 1 changed file with 4 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,12 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
return;
}

$error = 'Expected '.$comment;
$data = array($comment);
if (isset($tokens[($closingBracket + 1)]) === false || $tokens[($closingBracket + 1)]['code'] !== T_COMMENT) {
$next = $phpcsFile->findNext(T_WHITESPACE, ($closingBracket + 1), null, true);
if (rtrim($tokens[$next]['content']) === $comment) {
// The comment isn't really missing; it is just in the wrong place.
$fix = $phpcsFile->addFixableError($error.' directly after closing brace', $closingBracket, 'Misplaced');
$fix = $phpcsFile->addFixableError('Expected %s directly after closing brace', $closingBracket, 'Misplaced', $data);
if ($fix === true) {
$phpcsFile->fixer->beginChangeset();
for ($i = ($closingBracket + 1); $i < $next; $i++) {
Expand All @@ -125,7 +125,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
$phpcsFile->fixer->endChangeset();
}
} else {
$fix = $phpcsFile->addFixableError($error, $closingBracket, 'Missing');
$fix = $phpcsFile->addFixableError('Expected %s', $closingBracket, 'Missing', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken($closingBracket, '}'.$comment.$phpcsFile->eolChar);
}
Expand All @@ -135,7 +135,7 @@ public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr)
}//end if

if (rtrim($tokens[($closingBracket + 1)]['content']) !== $comment) {
$fix = $phpcsFile->addFixableError($error, $closingBracket, 'Incorrect');
$fix = $phpcsFile->addFixableError('Expected %s', $closingBracket, 'Incorrect', $data);
if ($fix === true) {
$phpcsFile->fixer->replaceToken(($closingBracket + 1), $comment.$phpcsFile->eolChar);
}
Expand Down

0 comments on commit b36d20b

Please sign in to comment.