Skip to content

Commit bdae03f

Browse files
authored
ForbidUnusedMatchResultRule: support nested matches (#106)
1 parent 25f397a commit bdae03f

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

src/Visitor/UnusedMatchVisitor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use PhpParser\Node\Expr\Throw_ as ThrowExpr;
1515
use PhpParser\Node\Expr\Yield_;
1616
use PhpParser\Node\Expr\YieldFrom;
17+
use PhpParser\Node\MatchArm;
1718
use PhpParser\Node\Stmt\Return_;
1819
use PhpParser\Node\Stmt\Throw_;
1920
use PhpParser\NodeVisitorAbstract;
@@ -82,6 +83,7 @@ private function isUsed(Node $parent): bool
8283
|| $parent instanceof ArrayItem
8384
|| $parent instanceof NullsafeMethodCall
8485
|| $parent instanceof Ternary
86+
|| $parent instanceof MatchArm
8587
|| $parent instanceof Yield_
8688
|| $parent instanceof YieldFrom
8789
|| $parent instanceof ThrowExpr;

tests/Rule/data/ForbidUnusedMatchResultRule/code.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,15 @@ public function testUsed(bool $bool): mixed
2424
true => "Bar",
2525
} ?? null;
2626

27+
$a = match ($int) {
28+
0 => $a = '0',
29+
1 => $b = '1',
30+
default => match ($bool) {
31+
false => "2",
32+
true => "3",
33+
},
34+
};
35+
2736
$this->use(match ($bool) {
2837
false => new LogicException(),
2938
true => new RuntimeException(),

0 commit comments

Comments
 (0)