Skip to content

Commit 2433886

Browse files
authored
Skip require a located namespace for anonymous exception (#190)
1 parent af9bfec commit 2433886

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

src/Rules/Domain/RequireExceptionNamespaceRule.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public function getNodeType(): string
3333
public function processNode(Node $node, Scope $scope): array
3434
{
3535
$classReflection = $node->getClassReflection();
36+
37+
if ($classReflection->isAnonymous()) {
38+
return [];
39+
}
40+
3641
if (! $classReflection->isClass()) {
3742
return [];
3843
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Domain\RequireExceptionNamespaceRule\Fixture;
6+
7+
new class () extends \Exception {};

tests/Rules/Domain/RequireExceptionNamespaceRule/RequireExceptionNamespaceRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public static function provideData(): Iterator
2525
{
2626
yield [__DIR__ . '/Fixture/MisslocatedException.php', [[RequireExceptionNamespaceRule::ERROR_MESSAGE, 9]]];
2727
yield [__DIR__ . '/Fixture/Exception/SkipCorrectException.php', []];
28+
yield [__DIR__ . '/Fixture/AnonymousException.php', []];
2829
}
2930

3031
/**

0 commit comments

Comments
 (0)