Skip to content

Commit

Permalink
ForbidUnusedMatchResultRule: support nested matches (#106)
Browse files Browse the repository at this point in the history
  • Loading branch information
janedbal committed Apr 21, 2023
1 parent 25f397a commit bdae03f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Visitor/UnusedMatchVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Expr\Throw_ as ThrowExpr;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\Expr\YieldFrom;
use PhpParser\Node\MatchArm;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_;
use PhpParser\NodeVisitorAbstract;
Expand Down Expand Up @@ -82,6 +83,7 @@ private function isUsed(Node $parent): bool
|| $parent instanceof ArrayItem
|| $parent instanceof NullsafeMethodCall
|| $parent instanceof Ternary
|| $parent instanceof MatchArm
|| $parent instanceof Yield_
|| $parent instanceof YieldFrom
|| $parent instanceof ThrowExpr;
Expand Down
9 changes: 9 additions & 0 deletions tests/Rule/data/ForbidUnusedMatchResultRule/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ public function testUsed(bool $bool): mixed
true => "Bar",
} ?? null;

$a = match ($int) {
0 => $a = '0',
1 => $b = '1',
default => match ($bool) {
false => "2",
true => "3",
},
};

$this->use(match ($bool) {
false => new LogicException(),
true => new RuntimeException(),
Expand Down

0 comments on commit bdae03f

Please sign in to comment.