You are here

public function Drupal_Sniffs_NamingConventions_ValidGlobalSniff::process in Coder 7.2

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

Parameters

PHP_CodeSniffer_File $phpcsFile The current file being processed.:

int $stackPtr The position of the current token: in the stack passed in $tokens.

Return value

void

File

coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php, line 93

Class

Drupal_Sniffs_NamingConventions_ValidGlobalSniff
Ensures that global variables start with an underscore.

Code

public function process(PHP_CodeSniffer_File $phpcsFile, $stackPtr) {
  $tokens = $phpcsFile
    ->getTokens();
  $varToken = $stackPtr;

  // Find variable names until we hit a semicolon.
  $ignore = PHP_CodeSniffer_Tokens::$emptyTokens;
  $ignore[] = T_SEMICOLON;
  while ($varToken = $phpcsFile
    ->findNext($ignore, $varToken + 1, null, true, null, true)) {
    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');
    }
  }
}