class NoSilencedErrorsSniff
Hierarchy
- class \PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\NoSilencedErrorsSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of NoSilencedErrorsSniff
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Generic/ Sniffs/ PHP/ NoSilencedErrorsSniff.php, line 22
Namespace
PHP_CodeSniffer\Standards\Generic\Sniffs\PHPView source
class NoSilencedErrorsSniff implements Sniff {
/**
* If true, an error will be thrown; otherwise a warning.
*
* @var boolean
*/
public $error = false;
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register() {
return [
T_ASPERAND,
];
}
//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile The file being scanned.
* @param int $stackPtr The position of the current token
* in the stack passed in $tokens.
*
* @return void
*/
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,
]);
}
}
//end process()
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
NoSilencedErrorsSniff::$error | public | property | If true, an error will be thrown; otherwise a warning. | |
NoSilencedErrorsSniff::process | public | function | Processes this test, when one of its tokens is encountered. | Overrides Sniff::process |
NoSilencedErrorsSniff::register | public | function | Returns an array of tokens this test wants to listen for. | Overrides Sniff::register |