Skip to content

Commit 7517d6e

Browse files
authored
forbidUnusedException: fix ::class access false positive (#299)
1 parent f038fad commit 7517d6e

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Visitor/UnusedExceptionVisitor.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use PhpParser\Node\ArrayItem;
88
use PhpParser\Node\Expr\Assign;
99
use PhpParser\Node\Expr\BinaryOp\Coalesce;
10+
use PhpParser\Node\Expr\ClassConstFetch;
1011
use PhpParser\Node\Expr\MethodCall;
1112
use PhpParser\Node\Expr\New_;
1213
use PhpParser\Node\Expr\NullsafeMethodCall;
@@ -94,6 +95,7 @@ private function isUsed(Node $parent): bool
9495
|| $parent instanceof Ternary
9596
|| $parent instanceof Yield_
9697
|| $parent instanceof Throw_
98+
|| $parent instanceof ClassConstFetch
9799
|| $parent instanceof MatchArm;
98100
}
99101

tests/Rule/data/ForbidUnusedExceptionRule/code.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,11 @@ public function okUsage7(string $decide): void
5959
};
6060
}
6161

62+
public function okUsage8(): void
63+
{
64+
echo $this->getException()::class;
65+
}
66+
6267
public function getExceptionAtRuntime(): RuntimeException
6368
{
6469
return new RuntimeException();

0 commit comments

Comments
 (0)