diff --git a/src/Visitor/UnusedExceptionVisitor.php b/src/Visitor/UnusedExceptionVisitor.php index b25e4db..4df2c53 100644 --- a/src/Visitor/UnusedExceptionVisitor.php +++ b/src/Visitor/UnusedExceptionVisitor.php @@ -7,6 +7,7 @@ use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Coalesce; +use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\NullsafeMethodCall; @@ -94,6 +95,7 @@ private function isUsed(Node $parent): bool || $parent instanceof Ternary || $parent instanceof Yield_ || $parent instanceof Throw_ + || $parent instanceof ClassConstFetch || $parent instanceof MatchArm; } diff --git a/tests/Rule/data/ForbidUnusedExceptionRule/code.php b/tests/Rule/data/ForbidUnusedExceptionRule/code.php index 22d83c2..f272875 100644 --- a/tests/Rule/data/ForbidUnusedExceptionRule/code.php +++ b/tests/Rule/data/ForbidUnusedExceptionRule/code.php @@ -59,6 +59,11 @@ public function okUsage7(string $decide): void }; } + public function okUsage8(): void + { + echo $this->getException()::class; + } + public function getExceptionAtRuntime(): RuntimeException { return new RuntimeException();