West/Sniffs/PHP/NoGlobalVarsSniff.php
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $token = $tokens[$stackPtr];

        $error = '';
        $data = [];
        switch ($token['type']) {
            case 'T_GLOBAL':
                $error   = 'Use of the "global" keyword is forbidden';
                $nextVar = $tokens[$phpcsFile->findNext([T_VARIABLE], $stackPtr)];
                $varName = str_replace('$', '', $nextVar['content']);
                $data    = [$varName];

                $phpcsFile->recordMetric($stackPtr, 'Global variable', 'yes');
                break;
            case 'T_VARIABLE':
                if ($token['content'] !== '$GLOBALS') {
                    return;
                }

                $error = 'Use of the "$GLOBALS" array is forbidden';
                $phpcsFile->recordMetric($stackPtr, 'Global variable', 'yes');
                break;
        }

        $phpcsFile->addError($error, $stackPtr, 'NotAllowed', $data);
    }
public function process(File $phpcsFile, $stackPtr)
    {
        $tokens = $phpcsFile->getTokens();
        $token = $tokens[$stackPtr];

        $error = '';
        $data = [];
        switch ($token['type']) {
            case 'T_GLOBAL':
                $error   = 'Use of the "global" keyword is forbidden';
                $nextVar = $tokens[$phpcsFile->findNext([T_VARIABLE], $stackPtr)];
                $varName = str_replace('$', '', $nextVar['content']);
                $data    = [$varName];

                $phpcsFile->recordMetric($stackPtr, 'Global variable', 'yes');
                break;
            case 'T_VARIABLE':
                if ($token['content'] !== '$GLOBALS') {
                    return;
                }

                $error = 'Use of the "$GLOBALS" array is forbidden';
                $phpcsFile->recordMetric($stackPtr, 'Global variable', 'yes');
                break;
        }

        $phpcsFile->addError($error, $stackPtr, 'NotAllowed', $data);
    }
{@inheritdoc}