getTokens(); // Check for the existence of the token. if (isset($tokens[$stackPtr]) === false) { return false; } // Is this one of the tokens this function handles ? if ($tokens[$stackPtr]['code'] !== \T_STRING) { return false; } $next = $phpcsFile->findNext(Tokens::$emptyTokens, ($stackPtr + 1), null, true); if ($next !== false && ($tokens[$next]['code'] === \T_OPEN_PARENTHESIS || $tokens[$next]['code'] === \T_DOUBLE_COLON) ) { // Function call or declaration. return false; } // Array of tokens which if found preceding the $stackPtr indicate that a T_STRING is not a global constant. $tokensToIgnore = [ \T_NAMESPACE => true, \T_USE => true, \T_EXTENDS => true, \T_IMPLEMENTS => true, \T_NEW => true, \T_FUNCTION => true, \T_INSTANCEOF => true, \T_INSTEADOF => true, \T_GOTO => true, \T_AS => true, ]; $tokensToIgnore += Tokens::$ooScopeTokens; $tokensToIgnore += Collections::objectOperators(); $tokensToIgnore += Tokens::$scopeModifiers; $prev = $phpcsFile->findPrevious(Tokens::$emptyTokens, ($stackPtr - 1), null, true); if ($prev !== false && isset($tokensToIgnore[$tokens[$prev]['code']]) === true) { // Not the use of a constant. return false; } if ($prev !== false && $tokens[$prev]['code'] === \T_NS_SEPARATOR && $tokens[($prev - 1)]['code'] === \T_STRING ) { // Namespaced constant of the same name. return false; } if ($prev !== false && $tokens[$prev]['code'] === \T_CONST && Scopes::isOOConstant($phpcsFile, $prev) === true ) { // Class constant declaration of the same name. return false; } /* * Deal with a number of variations of use statements. */ for ($i = $stackPtr; $i > 0; $i--) { if ($tokens[$i]['line'] !== $tokens[$stackPtr]['line']) { break; } } $firstOnLine = $phpcsFile->findNext(Tokens::$emptyTokens, ($i + 1), null, true); if ($firstOnLine !== false && $tokens[$firstOnLine]['code'] === \T_USE) { $nextOnLine = $phpcsFile->findNext(Tokens::$emptyTokens, ($firstOnLine + 1), null, true); if ($nextOnLine !== false) { if (($tokens[$nextOnLine]['code'] === \T_STRING && $tokens[$nextOnLine]['content'] === 'const')) { $hasNsSep = $phpcsFile->findNext(\T_NS_SEPARATOR, ($nextOnLine + 1), $stackPtr); if ($hasNsSep !== false) { // Namespaced const (group) use statement. return false; } } else { // Not a const use statement. return false; } } } return true; } }