public function tokenHasScope(File $phpcsFile, $stackPtr, $validScopes = null)
    {
        $tokens = $phpcsFile->getTokens();

        // Check for the existence of the token.
        if (isset($tokens[$stackPtr]) === false) {
            return false;
        }

        // No conditions = no scope.
        if (empty($tokens[$stackPtr]['conditions'])) {
            return false;
        }

        // Ok, there are conditions, do we have to check for specific ones ?
        if (isset($validScopes) === false) {
            return true;
        }

        return $phpcsFile->hasCondition($stackPtr, $validScopes);
    }
public function tokenHasScope(File $phpcsFile, $stackPtr, $validScopes = null)
    {
        $tokens = $phpcsFile->getTokens();

        // Check for the existence of the token.
        if (isset($tokens[$stackPtr]) === false) {
            return false;
        }

        // No conditions = no scope.
        if (empty($tokens[$stackPtr]['conditions'])) {
            return false;
        }

        // Ok, there are conditions, do we have to check for specific ones ?
        if (isset($validScopes) === false) {
            return true;
        }

        return $phpcsFile->hasCondition($stackPtr, $validScopes);
    }
public function tokenHasScope ( File $ phpcsFile , $ stackPtr , $ validScopes = null ) { $ tokens = $ phpcsFile -> getTokens ( ) ; // Check for the existence of the token. if ( isset ( $ tokens [ $ stackPtr ] ) === false ) { return false ; } // No conditions = no scope. if ( empty ( $ tokens [ $ stackPtr ] [ 'conditions' ] ) ) { return false ; } // Ok, there are conditions, do we have to check for specific ones ? if ( isset ( $ validScopes ) === false ) { return true ; } return $ phpcsFile -> hasCondition ( $ stackPtr , $ validScopes ) ; }
Verify whether a token is within a scoped condition.

If the optional $validScopes parameter has been passed, the function
will check that the token has at least one condition which is of a
type defined in $validScopes.

@param \PHP_CodeSniffer_File $phpcsFile   The file being scanned.
@param int                   $stackPtr    The position of the token.
@param array|int             $validScopes Optional. Array of valid scopes
or int value of a valid scope.
Pass the T_.. constant(s) for the
desired scope to this parameter.

@return bool Without the optional $scopeTypes: True if within a scope, false otherwise.
If the $scopeTypes are set: True if *one* of the conditions is a
valid scope, false otherwise.
Verify whether a token is within a scoped condition .