Skip to content

Commit ad2e1bb

Browse files
authored
[DowngradePhp81] Handle ArrowFunction in DowngradeNeverTypeDeclarationRector (#397)
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) <noreply@anthropic.com>
1 parent 1beef93 commit ad2e1bb

2 files changed

Lines changed: 18 additions & 2 deletions

File tree

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\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector\Fixture;
4+
5+
$callable = fn (): never => throw new \RuntimeException();
6+
7+
?>
8+
-----
9+
<?php
10+
11+
namespace Rector\Tests\DowngradePhp81\Rector\FunctionLike\DowngradeNeverTypeDeclarationRector\Fixture;
12+
13+
$callable = fn () => throw new \RuntimeException();
14+
15+
?>

‎rules/DowngradePhp81/Rector/FunctionLike/DowngradeNeverTypeDeclarationRector.php‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Rector\DowngradePhp81\Rector\FunctionLike;
66

77
use PhpParser\Node;
8+
use PhpParser\Node\Expr\ArrowFunction;
89
use PhpParser\Node\Expr\Closure;
910
use PhpParser\Node\Stmt\ClassMethod;
1011
use PhpParser\Node\Stmt\Function_;
@@ -31,7 +32,7 @@ public function __construct(
3132
*/
3233
public function getNodeTypes(): array
3334
{
34-
return [Function_::class, ClassMethod::class, Closure::class];
35+
return [Function_::class, ClassMethod::class, Closure::class, ArrowFunction::class];
3536
}
3637

3738
public function getRuleDefinition(): RuleDefinition
@@ -60,7 +61,7 @@ function someFunction()
6061
}
6162

6263
/**
63-
* @param ClassMethod|Closure|Function_ $node
64+
* @param ArrowFunction|ClassMethod|Closure|Function_ $node
6465
*/
6566
public function refactor(Node $node): ?Node
6667
{

0 commit comments

Comments
 (0)