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

Breadcrumb

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

function EmptyStatementSniff::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/CodeAnalysis/EmptyStatementSniff.php, line 68

Class

EmptyStatementSniff

Namespace

PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $token = $tokens[$stackPtr];
    // Skip statements without a body.
    if (isset($token['scope_opener']) === false) {
        return;
    }
    $next = $phpcsFile->findNext(Tokens::$emptyTokens, $token['scope_opener'] + 1, $token['scope_closer'] - 1, true);
    if ($next !== false) {
        return;
    }
    // Get token identifier.
    $name = strtoupper($token['content']);
    $error = 'Empty %s statement detected';
    $phpcsFile->addError($error, $stackPtr, 'Detected' . ucfirst(strtolower($name)), [
        $name,
    ]);
}
RSS feed
Powered by Drupal