public/phpmyadmin/vendor/squizlabs/php_codesniffer/src/Files/File.php
/**
     * Determine if the passed token is a reference operator.
     *
     * Returns true if the specified token position represents a reference.
     * Returns false if the token represents a bitwise operator.
     *
     * @param int $stackPtr The position of the T_BITWISE_AND token.
     *
     * @return boolean
     */
Determine if the passed token is a reference operator.
Returns true if the specified token position represents a reference.
Returns false if the token represents a bitwise operator.

@param int $stackPtr The position of the T_BITWISE_AND token.

@return boolean
Determine if the passed token is a reference operator . Returns true if the specified token position represents a reference . Returns false if the token represents a bitwise operator . @param int $stackPtr The position of the T_BITWISE_AND token . @return boolean
public function isReference($stackPtr)
    {
        if ($this->tokens[$stackPtr]['code'] !== T_BITWISE_AND) {
            return false;
        }
        $tokenBefore = $this->findPrevious(
            Util\Tokens::$emptyTokens,
            ($stackPtr - 1),
            null,
            true
        );
        if ($this->tokens[$tokenBefore]['code'] === T_FUNCTION) {
            return true;
        }
        if ($this->tokens[$tokenBefore]['code'] === T_DOUBLE_ARROW) {
            return true;
        }
        if ($this->tokens[$tokenBefore]['code'] === T_AS) {
            return true;
        }
        if (isset(Util\Tokens::$assignmentTokens[$this->tokens[$tokenBefore]['code']]) === true) {
            return true;
        }
        $tokenAfter = $this->findNext(
            Util\Tokens::$emptyTokens,
            ($stackPtr + 1),
            null,
            true
        );
        if ($this->tokens[$tokenAfter]['code'] === T_NEW) {
            return true;
        }
        if (isset($this->tokens[$stackPtr]['nested_parenthesis']) === true) {
            $brackets    = $this->tokens[$stackPtr]['nested_parenthesis'];
            $lastBracket = array_pop($brackets);
            if (isset($this->tokens[$lastBracket]['parenthesis_owner']) === true) {
                $owner = $this->tokens[$this->tokens[$lastBracket]['parenthesis_owner']];
                if ($owner['code'] === T_FUNCTION
                    || $owner['code'] === T_CLOSURE
                ) {
                    $params = $this->getMethodParameters($this->tokens[$lastBracket]['parenthesis_owner']);
                    foreach ($params as $param) {
                        $varToken = $tokenAfter;
                        if ($param['variable_length'] === true) {
                            $varToken = $this->findNext(
                                (Util\Tokens::$emptyTokens + [T_ELLIPSIS]),
                                ($stackPtr + 1),
                                null,
                                true
                            );
                        }
                        if ($param['token'] === $varToken
                            && $param['pass_by_reference'] === true
                        ) {
                            return true;
                        }
                    }
                }
            } else {
                $prev = false;
                for ($t = ($this->tokens[$lastBracket]['parenthesis_opener'] - 1); $t >= 0; $t--) {
                    if ($this->tokens[$t]['code'] !== T_WHITESPACE) {
                        $prev = $t;
                        break;
                    }
                }
                if ($prev !== false && $this->tokens[$prev]['code'] === T_USE) {
                    return true;
                }
            }
        }
        if ($this->tokens[$tokenBefore]['code'] === T_OPEN_PARENTHESIS
            || $this->tokens[$tokenBefore]['code'] === T_COMMA
            || $this->tokens[$tokenBefore]['code'] === T_OPEN_SHORT_ARRAY
        ) {
            if ($this->tokens[$tokenAfter]['code'] === T_VARIABLE) {
                return true;
            } else {
                $skip   = Util\Tokens::$emptyTokens;
                $skip[] = T_NS_SEPARATOR;
                $skip[] = T_SELF;
                $skip[] = T_PARENT;
                $skip[] = T_STATIC;
                $skip[] = T_STRING;
                $skip[] = T_NAMESPACE;
                $skip[] = T_DOUBLE_COLON;
                $nextSignificantAfter = $this->findNext(
                    $skip,
                    ($stackPtr + 1),
                    null,
                    true
                );
                if ($this->tokens[$nextSignificantAfter]['code'] === T_VARIABLE) {
                    return true;
                }
            }
        }
        return false;
    }
public function isReference ( $ stackPtr ) { if ( $ this -> tokens [ $ stackPtr ] [ 'code' ] !== T_BITWISE_AND ) { return false ; } $ tokenBefore = $ this -> findPrevious ( Util \ Tokens :: $ emptyTokens , ( $ stackPtr - 1 ) , null , true ) ; if ( $ this -> tokens [ $ tokenBefore ] [ 'code' ] === T_FUNCTION ) { return true ; } if ( $ this -> tokens [ $ tokenBefore ] [ 'code' ] === T_DOUBLE_ARROW ) { return true ; } if ( $ this -> tokens [ $ tokenBefore ] [ 'code' ] === T_AS ) { return true ; } if ( isset ( Util \ Tokens :: $ assignmentTokens [ $ this -> tokens [ $ tokenBefore ] [ 'code' ] ] ) === true ) { return true ; } $ tokenAfter = $ this -> findNext ( Util \ Tokens :: $ emptyTokens , ( $ stackPtr + 1 ) , null , true ) ; if ( $ this -> tokens [ $ tokenAfter ] [ 'code' ] === T_NEW ) { return true ; } if ( isset ( $ this -> tokens [ $ stackPtr ] [ 'nested_parenthesis' ] ) === true ) { $ brackets = $ this -> tokens [ $ stackPtr ] [ 'nested_parenthesis' ] ; $ lastBracket = array_pop ( $ brackets ) ; if ( isset ( $ this -> tokens [ $ lastBracket ] [ 'parenthesis_owner' ] ) === true ) { $ owner = $ this -> tokens [ $ this -> tokens [ $ lastBracket ] [ 'parenthesis_owner' ] ] ; if ( $ owner [ 'code' ] === T_FUNCTION || $ owner [ 'code' ] === T_CLOSURE ) { $ params = $ this -> getMethodParameters ( $ this -> tokens [ $ lastBracket ] [ 'parenthesis_owner' ] ) ; foreach ( $ params as $ param ) { $ varToken = $ tokenAfter ; if ( $ param [ 'variable_length' ] === true ) { $ varToken = $ this -> findNext ( ( Util \ Tokens :: $ emptyTokens + [ T_ELLIPSIS ] ) , ( $ stackPtr + 1 ) , null , true ) ; } if ( $ param [ 'token' ] === $ varToken && $ param [ 'pass_by_reference' ] === true ) { return true ; } } } } else { $ prev = false ; for ( $ t = ( $ this -> tokens [ $ lastBracket ] [ 'parenthesis_opener' ] - 1 ) ; $ t >= 0 ; $ t -- ) { if ( $ this -> tokens [ $ t ] [ 'code' ] !== T_WHITESPACE ) { $ prev = $ t ; break ; } } if ( $ prev !== false && $ this -> tokens [ $ prev ] [ 'code' ] === T_USE ) { return true ; } } } if ( $ this -> tokens [ $ tokenBefore ] [ 'code' ] === T_OPEN_PARENTHESIS || $ this -> tokens [ $ tokenBefore ] [ 'code' ] === T_COMMA || $ this -> tokens [ $ tokenBefore ] [ 'code' ] === T_OPEN_SHORT_ARRAY ) { if ( $ this -> tokens [ $ tokenAfter ] [ 'code' ] === T_VARIABLE ) { return true ; } else { $ skip = Util \ Tokens :: $ emptyTokens ; $ skip [ ] = T_NS_SEPARATOR ; $ skip [ ] = T_SELF ; $ skip [ ] = T_PARENT ; $ skip [ ] = T_STATIC ; $ skip [ ] = T_STRING ; $ skip [ ] = T_NAMESPACE ; $ skip [ ] = T_DOUBLE_COLON ; $ nextSignificantAfter = $ this -> findNext ( $ skip , ( $ stackPtr + 1 ) , null , true ) ; if ( $ this -> tokens [ $ nextSignificantAfter ] [ 'code' ] === T_VARIABLE ) { return true ; } } } return false ; }
Determine if the passed token is a reference operator.
Determine if the passed token is a reference operator .
// Function returns a reference. // Inside a foreach loop or array assignment, this is a reference. // Inside a foreach loop, this is a reference. // This is directly after an assignment. It's a reference. Even if // it is part of an operation, the other tests will handle it. // Function parameter declared to be passed by reference. //end if // Closure use by reference. //end if //end if // Pass by reference in function calls and assign by reference in arrays. //end if //end if