Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

unusedException: fix usage in match arm #90

Merged
merged 1 commit into from
Mar 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Visitor/UnusedExceptionVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Throw_ as ThrowExpr;
use PhpParser\Node\Expr\Yield_;
use PhpParser\Node\MatchArm;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Throw_;
use PhpParser\NodeVisitorAbstract;
Expand Down Expand Up @@ -94,7 +95,8 @@ private function isUsed(Node $parent): bool
|| $parent instanceof NullsafeMethodCall
|| $parent instanceof Ternary
|| $parent instanceof Yield_
|| $parent instanceof ThrowExpr;
|| $parent instanceof ThrowExpr
|| $parent instanceof MatchArm;
}

}
7 changes: 7 additions & 0 deletions tests/Rule/data/ForbidUnusedExceptionRule/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,13 @@ public function okUsage6(): \Generator
yield new \OutOfBoundsException();
}

public function okUsage7(string $decide): void
{
$exception = match ($decide) {
'foo' => new \OutOfRangeException(),
};
}

public function getExceptionAtRuntime(): RuntimeException
{
return new RuntimeException();
Expand Down