protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
    {
        $tokens = $phpcsFile->getTokens();

        $searchStartToken = $parameter['start'] - 1;
        $searchEndToken   = $parameter['end'] + 1;
        $nextVariable     = $searchStartToken;
        do {
            $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
            if ($nextVariable === false) {
                return false;
            }

            // Ignore anything within short array definition brackets.
            if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
                && (isset($tokens[$nextVariable]['bracket_opener'])
                    && $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
                && isset($tokens[$nextVariable]['bracket_closer'])
            ) {
                // Skip forward to the end of the short array definition.
                $nextVariable = $tokens[$nextVariable]['bracket_closer'];
                continue;
            }

            // Skip past closures passed as function parameters.
            if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
                && (isset($tokens[$nextVariable]['scope_condition'])
                    && $tokens[$nextVariable]['scope_condition'] === $nextVariable)
                && isset($tokens[$nextVariable]['scope_closer'])
            ) {
                // Skip forward to the end of the closure declaration.
                $nextVariable = $tokens[$nextVariable]['scope_closer'];
                continue;
            }

            // Make sure the variable belongs directly to this function call
            // and is not inside a nested function call or array.
            if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
                || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
            ) {
                continue;
            }

            // Checking this: $value = my_function(...[*]$arg...).
            $tokenBefore = $phpcsFile->findPrevious(
                Tokens::$emptyTokens,
                ($nextVariable - 1),
                $searchStartToken,
                true
            );

            if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
                // Nothing before the token or no &.
                continue;
            }

            if ($phpcsFile->isReference($tokenBefore) === false) {
                continue;
            }

            // Checking this: $value = my_function(...[*]&$arg...).
            $tokenBefore = $phpcsFile->findPrevious(
                Tokens::$emptyTokens,
                ($tokenBefore - 1),
                $searchStartToken,
                true
            );

            // Prevent false positive on assign by reference and compare with reference
            // within function call parameters.
            if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
                continue;
            }

            // The found T_BITWISE_AND represents a pass-by-reference.
            return true;

        } while ($nextVariable < $searchEndToken);

        // This code should never be reached, but here in case of weird bugs.
        return false;
    }
protected function isCallTimePassByReferenceParam(File $phpcsFile, $parameter, $nestingLevel)
    {
        $tokens = $phpcsFile->getTokens();

        $searchStartToken = $parameter['start'] - 1;
        $searchEndToken   = $parameter['end'] + 1;
        $nextVariable     = $searchStartToken;
        do {
            $nextVariable = $phpcsFile->findNext(array(\T_VARIABLE, \T_OPEN_SHORT_ARRAY, \T_CLOSURE), ($nextVariable + 1), $searchEndToken);
            if ($nextVariable === false) {
                return false;
            }

            // Ignore anything within short array definition brackets.
            if ($tokens[$nextVariable]['type'] === 'T_OPEN_SHORT_ARRAY'
                && (isset($tokens[$nextVariable]['bracket_opener'])
                    && $tokens[$nextVariable]['bracket_opener'] === $nextVariable)
                && isset($tokens[$nextVariable]['bracket_closer'])
            ) {
                // Skip forward to the end of the short array definition.
                $nextVariable = $tokens[$nextVariable]['bracket_closer'];
                continue;
            }

            // Skip past closures passed as function parameters.
            if ($tokens[$nextVariable]['type'] === 'T_CLOSURE'
                && (isset($tokens[$nextVariable]['scope_condition'])
                    && $tokens[$nextVariable]['scope_condition'] === $nextVariable)
                && isset($tokens[$nextVariable]['scope_closer'])
            ) {
                // Skip forward to the end of the closure declaration.
                $nextVariable = $tokens[$nextVariable]['scope_closer'];
                continue;
            }

            // Make sure the variable belongs directly to this function call
            // and is not inside a nested function call or array.
            if (isset($tokens[$nextVariable]['nested_parenthesis']) === false
                || (\count($tokens[$nextVariable]['nested_parenthesis']) !== $nestingLevel)
            ) {
                continue;
            }

            // Checking this: $value = my_function(...[*]$arg...).
            $tokenBefore = $phpcsFile->findPrevious(
                Tokens::$emptyTokens,
                ($nextVariable - 1),
                $searchStartToken,
                true
            );

            if ($tokenBefore === false || $tokens[$tokenBefore]['code'] !== \T_BITWISE_AND) {
                // Nothing before the token or no &.
                continue;
            }

            if ($phpcsFile->isReference($tokenBefore) === false) {
                continue;
            }

            // Checking this: $value = my_function(...[*]&$arg...).
            $tokenBefore = $phpcsFile->findPrevious(
                Tokens::$emptyTokens,
                ($tokenBefore - 1),
                $searchStartToken,
                true
            );

            // Prevent false positive on assign by reference and compare with reference
            // within function call parameters.
            if (isset($this->assignOrCompare[$tokens[$tokenBefore]['type']])) {
                continue;
            }

            // The found T_BITWISE_AND represents a pass-by-reference.
            return true;

        } while ($nextVariable < $searchEndToken);

        // This code should never be reached, but here in case of weird bugs.
        return false;
    }
protected function isCallTimePassByReferenceParam ( File $ phpcsFile , $ parameter , $ nestingLevel ) { $ tokens = $ phpcsFile -> getTokens ( ) ; $ searchStartToken = $ parameter [ 'start' ] - 1 ; $ searchEndToken = $ parameter [ 'end' ] + 1 ; $ nextVariable = $ searchStartToken ; do { $ nextVariable = $ phpcsFile -> findNext ( array ( \ T_VARIABLE , \ T_OPEN_SHORT_ARRAY , \ T_CLOSURE ) , ( $ nextVariable + 1 ) , $ searchEndToken ) ; if ( $ nextVariable === false ) { return false ; } // Ignore anything within short array definition brackets. if ( $ tokens [ $ nextVariable ] [ 'type' ] === 'T_OPEN_SHORT_ARRAY' && ( isset ( $ tokens [ $ nextVariable ] [ 'bracket_opener' ] ) && $ tokens [ $ nextVariable ] [ 'bracket_opener' ] === $ nextVariable ) && isset ( $ tokens [ $ nextVariable ] [ 'bracket_closer' ] ) ) { // Skip forward to the end of the short array definition. $ nextVariable = $ tokens [ $ nextVariable ] [ 'bracket_closer' ] ; continue ; } // Skip past closures passed as function parameters. if ( $ tokens [ $ nextVariable ] [ 'type' ] === 'T_CLOSURE' && ( isset ( $ tokens [ $ nextVariable ] [ 'scope_condition' ] ) && $ tokens [ $ nextVariable ] [ 'scope_condition' ] === $ nextVariable ) && isset ( $ tokens [ $ nextVariable ] [ 'scope_closer' ] ) ) { // Skip forward to the end of the closure declaration. $ nextVariable = $ tokens [ $ nextVariable ] [ 'scope_closer' ] ; continue ; } // Make sure the variable belongs directly to this function call // and is not inside a nested function call or array. if ( isset ( $ tokens [ $ nextVariable ] [ 'nested_parenthesis' ] ) === false || ( \ count ( $ tokens [ $ nextVariable ] [ 'nested_parenthesis' ] ) !== $ nestingLevel ) ) { continue ; } // Checking this: $value = my_function(...[*]$arg...). $ tokenBefore = $ phpcsFile -> findPrevious ( Tokens :: $ emptyTokens , ( $ nextVariable - 1 ) , $ searchStartToken , true ) ; if ( $ tokenBefore === false || $ tokens [ $ tokenBefore ] [ 'code' ] !== \ T_BITWISE_AND ) { // Nothing before the token or no &. continue ; } if ( $ phpcsFile -> isReference ( $ tokenBefore ) === false ) { continue ; } // Checking this: $value = my_function(...[*]&$arg...). $ tokenBefore = $ phpcsFile -> findPrevious ( Tokens :: $ emptyTokens , ( $ tokenBefore - 1 ) , $ searchStartToken , true ) ; // Prevent false positive on assign by reference and compare with reference // within function call parameters. if ( isset ( $ this -> assignOrCompare [ $ tokens [ $ tokenBefore ] [ 'type' ] ] ) ) { continue ; } // The found T_BITWISE_AND represents a pass-by-reference. return true ; } while ( $ nextVariable < $ searchEndToken ) ; // This code should never be reached, but here in case of weird bugs. return false ; }
Determine whether a parameter is passed by reference.

@param \PHP_CodeSniffer_File $phpcsFile    The file being scanned.
@param array                 $parameter    Information on the current parameter
to be examined.
@param int                   $nestingLevel Target nesting level.

@return bool
Determine whether a parameter is passed by reference .