From 03183a1946a72439aee4399dd3d0566c38644034 Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Tue, 8 Sep 2026 16:33:35 +0400 Subject: [PATCH] [DowngradePhp81] Handle ArrowFunction in DowngradeNeverTypeDeclarationRector A "never" return type on an arrow function is invalid below PHP 8.1, yet the rule only subscribed to Function_, ClassMethod and Closure, so fn(): never => ... was left untouched. Add ArrowFunction to the subscribed node types; the decorator already accepts it. Assisted-By: Claude Opus 4.8 (1M context) --- .../Fixture/arrow_function_never.php.inc | 15 +++++++++++++++ .../DowngradeNeverTypeDeclarationRector.php | 5 +++-- 2 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/arrow_function_never.php.inc diff --git a/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/arrow_function_never.php.inc b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/arrow_function_never.php.inc new file mode 100644 index 00000000..f5d11194 --- /dev/null +++ b/rules-tests/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector/Fixture/arrow_function_never.php.inc @@ -0,0 +1,15 @@ + throw new \RuntimeException(); + +?> +----- + throw new \RuntimeException(); + +?> diff --git a/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php b/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php index f7d958f7..4c0203f9 100644 --- a/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php +++ b/rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php @@ -5,6 +5,7 @@ namespace Rector\DowngradePhp81\Rector\FunctionLike; use PhpParser\Node; +use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; @@ -31,7 +32,7 @@ public function __construct( */ public function getNodeTypes(): array { - return [Function_::class, ClassMethod::class, Closure::class]; + return [Function_::class, ClassMethod::class, Closure::class, ArrowFunction::class]; } public function getRuleDefinition(): RuleDefinition @@ -60,7 +61,7 @@ function someFunction() } /** - * @param ClassMethod|Closure|Function_ $node + * @param ArrowFunction|ClassMethod|Closure|Function_ $node */ public function refactor(Node $node): ?Node {