From cb44ce35a07341cd4409a636be2d1352b19e80ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20=C5=A0t=C3=ADpek?= Date: Wed, 28 May 2025 11:55:17 +0200 Subject: [PATCH] ForbidUnusedMatchResultRule: count match implicitly returned by arrow function as used --- src/Visitor/UnusedMatchVisitor.php | 4 +++- tests/Rule/data/ForbidUnusedMatchResultRule/code.php | 12 ++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/Visitor/UnusedMatchVisitor.php b/src/Visitor/UnusedMatchVisitor.php index f30168d..d1c137d 100644 --- a/src/Visitor/UnusedMatchVisitor.php +++ b/src/Visitor/UnusedMatchVisitor.php @@ -5,6 +5,7 @@ use PhpParser\Node; use PhpParser\Node\Arg; use PhpParser\Node\ArrayItem; +use PhpParser\Node\Expr\ArrowFunction; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\AssignOp; use PhpParser\Node\Expr\BinaryOp\Coalesce; @@ -86,7 +87,8 @@ private function isUsed(Node $parent): bool || $parent instanceof Ternary || $parent instanceof MatchArm || $parent instanceof Yield_ - || $parent instanceof YieldFrom; + || $parent instanceof YieldFrom + || $parent instanceof ArrowFunction; } } diff --git a/tests/Rule/data/ForbidUnusedMatchResultRule/code.php b/tests/Rule/data/ForbidUnusedMatchResultRule/code.php index f96c8ce..df26b30 100644 --- a/tests/Rule/data/ForbidUnusedMatchResultRule/code.php +++ b/tests/Rule/data/ForbidUnusedMatchResultRule/code.php @@ -70,6 +70,18 @@ public function testUsed(bool $bool): mixed 1 => 'y', } : null; + function ($int) { + return match ($int) { + 0 => 'x', + 1 => 'y', + }; + }; + + fn () => match ($int) { + 0 => 'x', + 1 => 'y', + }; + return match ($bool) { false => 1, true => 2,