PhpCsFixer\Fixer\Alias\PowToExponentiationFixer::fixPowToExponentiation PHP Method

fixPowToExponentiation() private method

private fixPowToExponentiation ( Tokens $tokens, integer $functionNameIndex, integer $openParenthesisIndex, integer $closeParenthesisIndex, array $arguments ) : integer
$tokens PhpCsFixer\Tokenizer\Tokens
$functionNameIndex integer
$openParenthesisIndex integer
$closeParenthesisIndex integer
$arguments array
return integer number of tokens added to the collection
    private function fixPowToExponentiation(Tokens $tokens, $functionNameIndex, $openParenthesisIndex, $closeParenthesisIndex, array $arguments)
    {
        // find the argument separator ',' directly after the last token of the first argument;
        // replace it with T_POW '**'
        $tokens->overrideAt($tokens->getNextTokenOfKind(reset($arguments), array(',')), new Token(array(T_POW, '**')));
        // clean up the function call tokens prt. I
        $tokens[$closeParenthesisIndex]->clear();
        $added = 0;
        // check if the arguments need to be wrapped in parenthesis
        foreach (array_reverse($arguments, true) as $argumentStartIndex => $argumentEndIndex) {
            if ($this->isParenthesisNeeded($tokens, $argumentStartIndex, $argumentEndIndex)) {
                $tokens->insertAt($argumentEndIndex + 1, new Token(')'));
                $tokens->insertAt($argumentStartIndex, new Token('('));
                $added += 2;
            }
        }
        // clean up the function call tokens prt. II
        $tokens[$openParenthesisIndex]->clear();
        $tokens[$functionNameIndex]->clear();
        $prev = $tokens->getPrevMeaningfulToken($functionNameIndex);
        if ($tokens[$prev]->isGivenKind(T_NS_SEPARATOR)) {
            $tokens[$prev]->clear();
        }
        return $added;
    }