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

Breadcrumb

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

function ExpectedExceptionSniff::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/drupal/coder/coder_sniffer/DrupalPractice/Sniffs/Commenting/ExpectedExceptionSniff.php, line 49

Class

ExpectedExceptionSniff
Checks that the PHPunit @expectedException tags are not used.

Namespace

DrupalPractice\Sniffs\Commenting

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $content = $tokens[$stackPtr]['content'];
    if ($content === '@expectedException' || $content === '@expectedExceptionCode' || $content === '@expectedExceptionMessage' || $content === '@expectedExceptionMessageRegExp') {
        $warning = '%s tags should not be used, use $this->setExpectedException() or $this->expectException() instead';
        $phpcsFile->addWarning($warning, $stackPtr, 'TagFound', [
            $content,
        ]);
    }
}
RSS feed
Powered by Drupal