src/ETSGlobalCodingStandard/Helpers/ArgumentHelper.php
/**
     * Find an argument passed to a function call.
     *
     * @param int   $openParenthesisPointer The pointer to the function call opening parenthesis.
     * @param int   $argumentNumber         The position number of the argument looked for.
     *
     * @return int|null                     The pointer to desired argument, null if argument does not exist.
     */
Find an argument passed to a function call.
@param int   $openParenthesisPointer The pointer to the function call opening parenthesis.
@param int   $argumentNumber         The position number of the argument looked for.

@return int|null                     The pointer to desired argument, null if argument does not exist.
Find an argument passed to a function call . @param int $openParenthesisPointer The pointer to the function call opening parenthesis . @param int $argumentNumber The position number of the argument looked for . @return int|null The pointer to desired argument null if argument does not exist .
public static function findArgumentPointer(File $phpcsFile, int $openParenthesisPointer, int $argumentNumber = 1): ?int
    {
        $tokens = $phpcsFile->getTokens();
        $openParenthesis = $tokens[$openParenthesisPointer];
        $closeParenthesisPointer = $openParenthesis['parenthesis_closer'];
        $currentPointer = $openParenthesisPointer + 1;
        $currentArgumentNumber = 1;
        while ($currentPointer < $closeParenthesisPointer) {
            $nextDelimiterPointer = $phpcsFile->findEndOfStatement($currentPointer, [T_DOUBLE_ARROW]);
            if ($currentArgumentNumber === $argumentNumber) {
                $argumentPointer = TokenHelper::findNextEffective($phpcsFile, $currentPointer, $nextDelimiterPointer);
                if (!$argumentPointer) {
                    return null;
                }
                return $argumentPointer;
            }
            if ($nextDelimiterPointer === $closeParenthesisPointer) {
                break;
            }
            $currentPointer = $nextDelimiterPointer + 1;
            $currentArgumentNumber++;
        }
        return null;
    }
public static function findArgumentPointer ( File $ phpcsFile , int $ openParenthesisPointer , int $ argumentNumber = 1 ) : ? int { $ tokens = $ phpcsFile -> getTokens ( ) ; $ openParenthesis = $ tokens [ $ openParenthesisPointer ] ; $ closeParenthesisPointer = $ openParenthesis [ 'parenthesis_closer' ] ; $ currentPointer = $ openParenthesisPointer + 1 ; $ currentArgumentNumber = 1 ; while ( $ currentPointer < $ closeParenthesisPointer ) { $ nextDelimiterPointer = $ phpcsFile -> findEndOfStatement ( $ currentPointer , [ T_DOUBLE_ARROW ] ) ; if ( $ currentArgumentNumber === $ argumentNumber ) { $ argumentPointer = TokenHelper :: findNextEffective ( $ phpcsFile , $ currentPointer , $ nextDelimiterPointer ) ; if ( ! $ argumentPointer ) { return null ; } return $ argumentPointer ; } if ( $ nextDelimiterPointer === $ closeParenthesisPointer ) { break ; } $ currentPointer = $ nextDelimiterPointer + 1 ; $ currentArgumentNumber ++ ; } return null ; }
Find an argument passed to a function call.
Find an argument passed to a function call .
// Cannot find any valid argument // Next delimiter is the closing parenthesis, there is no more argument.