|
@@ -30,7 +30,7 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
|
|
|
*/
|
|
|
public function isCandidate(Tokens $tokens)
|
|
|
{
|
|
|
- // minimal candidate to fix is seven tokens: pow(x,x);
|
|
|
+ // minimal candidate to fix is seven tokens: pow(x,y);
|
|
|
return $tokens->count() > 7 && $tokens->isTokenKindFound(T_STRING);
|
|
|
}
|
|
|
|
|
@@ -68,9 +68,9 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
|
|
|
{
|
|
|
$candidates = $this->findPowCalls($tokens);
|
|
|
$argumentsAnalyzer = new ArgumentsAnalyzer();
|
|
|
-
|
|
|
$numberOfTokensAdded = 0;
|
|
|
$previousCloseParenthesisIndex = \count($tokens);
|
|
|
+
|
|
|
foreach (array_reverse($candidates) as $candidate) {
|
|
|
// if in the previous iteration(s) tokens were added to the collection and this is done within the tokens
|
|
|
// indexes of the current candidate than the index of the close ')' of the candidate has moved and so
|
|
@@ -84,10 +84,17 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
|
|
|
}
|
|
|
|
|
|
$arguments = $argumentsAnalyzer->getArguments($tokens, $candidate[1], $candidate[2]);
|
|
|
+
|
|
|
if (2 !== \count($arguments)) {
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
+ for ($i = $candidate[1]; $i < $candidate[2]; ++$i) {
|
|
|
+ if ($tokens[$i]->isGivenKind(T_ELLIPSIS)) {
|
|
|
+ continue 2;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
$numberOfTokensAdded += $this->fixPowToExponentiation(
|
|
|
$tokens,
|
|
|
$candidate[0], // functionNameIndex,
|
|
@@ -105,12 +112,13 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
|
|
|
{
|
|
|
$candidates = [];
|
|
|
|
|
|
- // Minimal candidate to fix is seven tokens: pow(x,x);
|
|
|
+ // Minimal candidate to fix is seven tokens: pow(x,y);
|
|
|
$end = \count($tokens) - 6;
|
|
|
|
|
|
// First possible location is after the open token: 1
|
|
|
for ($i = 1; $i < $end; ++$i) {
|
|
|
$candidate = $this->find('pow', $tokens, $i, $end);
|
|
|
+
|
|
|
if (null === $candidate) {
|
|
|
break;
|
|
|
}
|
|
@@ -139,11 +147,13 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
|
|
|
// clean up the function call tokens prt. I
|
|
|
$tokens->clearAt($closeParenthesisIndex);
|
|
|
$previousIndex = $tokens->getPrevMeaningfulToken($closeParenthesisIndex);
|
|
|
+
|
|
|
if ($tokens[$previousIndex]->equals(',')) {
|
|
|
$tokens->clearAt($previousIndex); // trailing ',' in function call (PHP 7.3)
|
|
|
}
|
|
|
|
|
|
$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)) {
|
|
@@ -157,9 +167,10 @@ final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
|
|
|
$tokens->clearAt($openParenthesisIndex);
|
|
|
$tokens->clearAt($functionNameIndex);
|
|
|
|
|
|
- $prev = $tokens->getPrevMeaningfulToken($functionNameIndex);
|
|
|
- if ($tokens[$prev]->isGivenKind(T_NS_SEPARATOR)) {
|
|
|
- $tokens->clearAt($prev);
|
|
|
+ $prevMeaningfulTokenIndex = $tokens->getPrevMeaningfulToken($functionNameIndex);
|
|
|
+
|
|
|
+ if ($tokens[$prevMeaningfulTokenIndex]->isGivenKind(T_NS_SEPARATOR)) {
|
|
|
+ $tokens->clearAt($prevMeaningfulTokenIndex);
|
|
|
}
|
|
|
|
|
|
return $added;
|