diff --git a/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector/Fixture/with_named_arg.php.inc b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector/Fixture/with_named_arg.php.inc new file mode 100644 index 00000000..f2115509 --- /dev/null +++ b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector/Fixture/with_named_arg.php.inc @@ -0,0 +1,15 @@ + +----- + diff --git a/rules/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector.php b/rules/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector.php index f6786555..0f0c3088 100644 --- a/rules/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector.php +++ b/rules/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector.php @@ -5,6 +5,7 @@ namespace Rector\DowngradePhp84\Rector\FuncCall; use PhpParser\Node; +use PhpParser\Node\Arg; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\FuncCall; @@ -58,17 +59,12 @@ public function refactor(Node $node): ?Node return null; } - $args = $node->getArgs(); - - if (count($args) !== 3) { - return null; - } - - if (! isset($args[2])) { + $arg = $node->getArg('mode', 2); + if (! $arg instanceof Arg) { return null; } - $modeArg = $args[2]->value; + $modeArg = $arg->value; $hasChanged = false; if ($modeArg instanceof ClassConstFetch && $modeArg->class instanceof FullyQualified && $this->isName( $modeArg->class, @@ -89,7 +85,7 @@ public function refactor(Node $node): ?Node return null; } - $args[2]->value = new ConstFetch(new FullyQualified($constantName)); + $arg->value = new ConstFetch(new FullyQualified($constantName)); $hasChanged = true; }