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

Breadcrumb

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

function ValidGlobalSniff::process

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

Parameters

\PHP_CodeSniffer\Files\File $phpcsFile The current file being processed.:

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/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php, line 104

Class

ValidGlobalSniff
Ensures that global variables start with an underscore.

Namespace

Drupal\Sniffs\NamingConventions

Code

public function process(File $phpcsFile, $stackPtr) {
    $tokens = $phpcsFile->getTokens();
    $varToken = $stackPtr;
    // Find variable names until we hit a semicolon.
    $ignore = Tokens::$emptyTokens;
    $ignore[] = T_SEMICOLON;
    while (($varToken = $phpcsFile->findNext($ignore, $varToken + 1, null, true, null, true)) !== false) {
        if ($tokens[$varToken]['code'] === T_VARIABLE && in_array($tokens[$varToken]['content'], $this->coreGlobals) === false && $tokens[$varToken]['content'][1] !== '_') {
            $error = 'global variables should start with a single underscore followed by the module and another underscore';
            $phpcsFile->addError($error, $varToken, 'GlobalUnderScore');
        }
    }
}
RSS feed
Powered by Drupal