function NoSilencedErrorsSniff::process
Processes this test, when one of its tokens is encountered.
Parameters
\PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.:
int $stackPtr The position of the current token: in the stack passed in $tokens.
Return value
void
Overrides Sniff::process
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ PHP/ NoSilencedErrorsSniff.php, line 54
Class
Namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\PHPCode
public function process(File $phpcsFile, $stackPtr) {
// Prepare the "Found" string to display.
$contextLength = 4;
$endOfStatement = $phpcsFile->findEndOfStatement($stackPtr, [
T_COMMA,
T_COLON,
]);
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; found: %s';
$phpcsFile->addError($error, $stackPtr, 'Forbidden', [
$found,
]);
}
else {
$error = 'Silencing errors is discouraged; found: %s';
$phpcsFile->addWarning($error, $stackPtr, 'Discouraged', [
$found,
]);
}
}