public function ValidGlobalSniff::process in Coder 8.2
Same name and namespace in other branches
- 8.3 coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php \Drupal\Sniffs\NamingConventions\ValidGlobalSniff::process()
- 8.3.x coder_sniffer/Drupal/Sniffs/NamingConventions/ValidGlobalSniff.php \Drupal\Sniffs\NamingConventions\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
File
- coder_sniffer/
Drupal/ Sniffs/ NamingConventions/ ValidGlobalSniff.php, line 98
Class
- ValidGlobalSniff
- Ensures that global variables start with an underscore.
Namespace
Drupal\Sniffs\NamingConventionsCode
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');
}
}
}