Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
GlobalVariablesSniff.php
Go to the documentation of this file.
1 <?php
8 
9 use PHP_CodeSniffer\Sniffs\Sniff;
10 use PHP_CodeSniffer\Files\File;
11 
15 class GlobalVariablesSniff implements Sniff
16 {
20  public function register()
21  {
22  return [T_VARIABLE];
23  }
24 
28  public function process(File $phpcsFile, $stackPtr)
29  {
30  $tokens = $phpcsFile->getTokens();
31  if (preg_match('/^\$[_A-Z0-9]+$/', $tokens[$stackPtr]['content'])) {
32  $phpcsFile->addError(
33  'Usage of global variables is not allowed: ' . $tokens[$stackPtr]['content'],
34  $stackPtr,
35  'ERROR'
36  );
37  return;
38  }
39  }
40 }
$tokens
Definition: cards_list.phtml:9