Skip to content

Commit 7773b7b

Browse files
authored
[DowngradePhp84] Allow named arg on DowngradeRoundingModeEnumRector (#335)
1 parent 7730326 commit 7773b7b

File tree

2 files changed

+20
-9
lines changed

2 files changed

+20
-9
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php84\Rector\FuncCall\RoundingModeEnumRector;
4+
5+
round(precision: 0, mode: \RoundingMode::HalfAwayFromZero, value: 1.5);
6+
7+
?>
8+
-----
9+
<?php
10+
11+
namespace Rector\Tests\Php84\Rector\FuncCall\RoundingModeEnumRector;
12+
13+
round(precision: 0, mode: \PHP_ROUND_HALF_UP, value: 1.5);
14+
15+
?>

rules/DowngradePhp84/Rector/FuncCall/DowngradeRoundingModeEnumRector.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Rector\DowngradePhp84\Rector\FuncCall;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\Arg;
89
use PhpParser\Node\Expr\ClassConstFetch;
910
use PhpParser\Node\Expr\ConstFetch;
1011
use PhpParser\Node\Expr\FuncCall;
@@ -58,17 +59,12 @@ public function refactor(Node $node): ?Node
5859
return null;
5960
}
6061

61-
$args = $node->getArgs();
62-
63-
if (count($args) !== 3) {
64-
return null;
65-
}
66-
67-
if (! isset($args[2])) {
62+
$arg = $node->getArg('mode', 2);
63+
if (! $arg instanceof Arg) {
6864
return null;
6965
}
7066

71-
$modeArg = $args[2]->value;
67+
$modeArg = $arg->value;
7268
$hasChanged = false;
7369
if ($modeArg instanceof ClassConstFetch && $modeArg->class instanceof FullyQualified && $this->isName(
7470
$modeArg->class,
@@ -89,7 +85,7 @@ public function refactor(Node $node): ?Node
8985
return null;
9086
}
9187

92-
$args[2]->value = new ConstFetch(new FullyQualified($constantName));
88+
$arg->value = new ConstFetch(new FullyQualified($constantName));
9389
$hasChanged = true;
9490
}
9591

0 commit comments

Comments
 (0)