From 6ea5e042ca7f08dff9df12abeade4869c422bdcd Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 7 Aug 2026 17:19:58 +0700 Subject: [PATCH 1/4] [DowngradePhp84] Add DowngradeExitNamedArgumentRector --- config/set/downgrade-php84.php | 2 + .../DowngradeExitNamedArgumentRectorTest.php | 28 +++++++ .../Fixture/fixture.php.inc | 33 +++++++++ .../skip_without_named_argument.php.inc | 13 ++++ .../config/configured_rule.php | 10 +++ .../DowngradeExitNamedArgumentRector.php | 73 +++++++++++++++++++ 6 files changed, 159 insertions(+) create mode 100644 rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/DowngradeExitNamedArgumentRectorTest.php create mode 100644 rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/fixture.php.inc create mode 100644 rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/skip_without_named_argument.php.inc create mode 100644 rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/config/configured_rule.php create mode 100644 rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php diff --git a/config/set/downgrade-php84.php b/config/set/downgrade-php84.php index 6972a98f..2a920783 100644 --- a/config/set/downgrade-php84.php +++ b/config/set/downgrade-php84.php @@ -7,6 +7,7 @@ use Rector\DowngradePhp84\Rector\Expression\DowngradeArrayAnyRector; use Rector\DowngradePhp84\Rector\Expression\DowngradeArrayFindKeyRector; use Rector\DowngradePhp84\Rector\Expression\DowngradeArrayFindRector; +use Rector\DowngradePhp84\Rector\FuncCall\DowngradeExitNamedArgumentRector; use Rector\DowngradePhp84\Rector\FuncCall\DowngradeRoundingModeEnumRector; use Rector\DowngradePhp84\Rector\MethodCall\DowngradeNewMethodCallWithoutParenthesesRector; use Rector\ValueObject\PhpVersion; @@ -15,6 +16,7 @@ $rectorConfig->phpVersion(PhpVersion::PHP_83); $rectorConfig->rules([ DowngradeNewMethodCallWithoutParenthesesRector::class, + DowngradeExitNamedArgumentRector::class, DowngradeRoundingModeEnumRector::class, DowngradeArrayAllRector::class, DowngradeArrayAnyRector::class, diff --git a/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/DowngradeExitNamedArgumentRectorTest.php b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/DowngradeExitNamedArgumentRectorTest.php new file mode 100644 index 00000000..50dd8708 --- /dev/null +++ b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/DowngradeExitNamedArgumentRectorTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFilesFromDirectory(__DIR__ . '/Fixture'); + } + + public function provideConfigFilePath(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/fixture.php.inc b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/fixture.php.inc new file mode 100644 index 00000000..f5ec55cc --- /dev/null +++ b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/fixture.php.inc @@ -0,0 +1,33 @@ + +----- + diff --git a/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/skip_without_named_argument.php.inc b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/skip_without_named_argument.php.inc new file mode 100644 index 00000000..7838cd66 --- /dev/null +++ b/rules-tests/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector/Fixture/skip_without_named_argument.php.inc @@ -0,0 +1,13 @@ +rule(DowngradeExitNamedArgumentRector::class); +}; diff --git a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php new file mode 100644 index 00000000..aee92c27 --- /dev/null +++ b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php @@ -0,0 +1,73 @@ +> + */ + public function getNodeTypes(): array + { + return [FuncCall::class]; + } + + /** + * @param FuncCall $node + */ + public function refactor(Node $node): ?Node + { + if (! $this->isNames($node, ['exit', 'die'])) { + return null; + } + + if ($node->isFirstClassCallable()) { + return null; + } + + $statusArg = $node->getArg('status', 0); + if (! $statusArg instanceof Arg) { + return null; + } + + if (! $statusArg->name instanceof Identifier) { + return null; + } + + $node->args[0]->name = null; + return $node; + } +} From 65caf5c015cb09f5a1329a689b6b8a16aff98edf Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 7 Aug 2026 17:23:44 +0700 Subject: [PATCH 2/4] Fix phpstan --- .../FuncCall/DowngradeExitNamedArgumentRector.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php index aee92c27..b5b8b07a 100644 --- a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php +++ b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php @@ -58,7 +58,12 @@ public function refactor(Node $node): ?Node return null; } - $statusArg = $node->getArg('status', 0); + $args = $node->getArgs(); + if (count($args) !== 1) { + return null; + } + + $statusArg = $args[0]; if (! $statusArg instanceof Arg) { return null; } @@ -67,7 +72,9 @@ public function refactor(Node $node): ?Node return null; } - $node->args[0]->name = null; + $args[0]->name = null; + $node->args = $args; + return $node; } } From 994b896165e84f674a04c6cd8007db3551c304c9 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 7 Aug 2026 17:24:37 +0700 Subject: [PATCH 3/4] clean up --- .../Rector/FuncCall/DowngradeExitNamedArgumentRector.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php index b5b8b07a..691c4fbf 100644 --- a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php +++ b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php @@ -73,8 +73,6 @@ public function refactor(Node $node): ?Node } $args[0]->name = null; - $node->args = $args; - return $node; } } From 2399bb553ae27ba4469296084e2fe8af46c62369 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Fri, 7 Aug 2026 17:26:37 +0700 Subject: [PATCH 4/4] clean up --- .../Rector/FuncCall/DowngradeExitNamedArgumentRector.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php index 691c4fbf..198523b7 100644 --- a/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php +++ b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php @@ -72,7 +72,7 @@ public function refactor(Node $node): ?Node return null; } - $args[0]->name = null; + $statusArg->name = null; return $node; } }