Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. EmptyCatchCommentSniff.php

function EmptyCatchCommentSniff::process

Processes this test, when one of its tokens is encountered.

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile All the tokens found in the document.:

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/Squiz/Sniffs/Commenting/EmptyCatchCommentSniff.php, line 40

Class

EmptyCatchCommentSniff

Namespace

PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting

Code

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');
    }
}
RSS feed
Powered by Drupal