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..198523b7 --- /dev/null +++ b/rules/DowngradePhp84/Rector/FuncCall/DowngradeExitNamedArgumentRector.php @@ -0,0 +1,78 @@ +> + */ + 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; + } + + $args = $node->getArgs(); + if (count($args) !== 1) { + return null; + } + + $statusArg = $args[0]; + if (! $statusArg instanceof Arg) { + return null; + } + + if (! $statusArg->name instanceof Identifier) { + return null; + } + + $statusArg->name = null; + return $node; + } +}