class EmptyCatchCommentSniff
Hierarchy
- class \PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\EmptyCatchCommentSniff implements \PHP_CodeSniffer\Sniffs\Sniff
Expanded class hierarchy of EmptyCatchCommentSniff
File
-
vendor/
squizlabs/ php_codesniffer/ src/ Standards/ Squiz/ Sniffs/ Commenting/ EmptyCatchCommentSniff.php, line 15
Namespace
PHP_CodeSniffer\Standards\Squiz\Sniffs\CommentingView source
class EmptyCatchCommentSniff implements Sniff {
/**
* Returns an array of tokens this test wants to listen for.
*
* @return array<int|string>
*/
public function register() {
return [
T_CATCH,
];
}
//end register()
/**
* Processes this test, when one of its tokens is encountered.
*
* @param \PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.
* @param int $stackPtr The position of the current token in the
* stack passed in $tokens.
*
* @return void
*/
public function process(File $phpcsFile, $stackPtr) {
$tokens = $phpcsFile->getTokens();
$scopeStart = $tokens[$stackPtr]['scope_opener'];
$firstContent = $phpcsFile->findNext(T_WHITESPACE, $scopeStart + 1, $tokens[$stackPtr]['scope_closer'], true);
if ($firstContent === false) {
$error = 'Empty CATCH statement must have a comment to explain why the exception is not handled';
$phpcsFile->addError($error, $scopeStart, 'Missing');
}
}
//end process()
}
Members
Title Sort descending | Modifiers | Object type | Summary | Overriden Title |
---|---|---|---|---|
EmptyCatchCommentSniff::process | public | function | Processes this test, when one of its tokens is encountered. | Overrides Sniff::process |
EmptyCatchCommentSniff::register | public | function | Returns an array of tokens this test wants to listen for. | Overrides Sniff::register |