Skip to content

Commit

Permalink
Merge branch 'feature/generic-nosilencederrors-improve-usefulness-err…
Browse files Browse the repository at this point in the history
  • Loading branch information
gsherwood committed Aug 23, 2018
2 parents 17089a7 + 1c97322 commit 223ad31
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions src/Standards/Generic/Sniffs/PHP/NoSilencedErrorsSniff.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,12 +53,22 @@ public function register()
*/
public function process(File $phpcsFile, $stackPtr)
{
// Prepare the "Found" string to display.
$contextLength = 4;
$endOfStatement = $phpcsFile->findEndOfStatement($stackPtr, T_COMMA);
if (($endOfStatement - $stackPtr) < $contextLength) {
$contextLength = ($endOfStatement - $stackPtr);
}

$found = $phpcsFile->getTokensAsString($stackPtr, $contextLength);
$found = str_replace(["\t", "\n", "\r"], ' ', $found).'...';

if ($this->error === true) {
$error = 'Silencing errors is forbidden';
$phpcsFile->addError($error, $stackPtr, 'Forbidden');
$error = 'Silencing errors is forbidden. Found: %s';
$phpcsFile->addError($error, $stackPtr, 'Forbidden', [$found]);
} else {
$error = 'Silencing errors is discouraged';
$phpcsFile->addWarning($error, $stackPtr, 'Discouraged');
$error = 'Silencing errors is discouraged. Found: %s';
$phpcsFile->addWarning($error, $stackPtr, 'Discouraged', [$found]);
}

}//end process()
Expand Down

0 comments on commit 223ad31

Please sign in to comment.