Skip to content

Commit 072479b

Browse files
authored
Merge branch 'main' into support-attributes-for-event-listener
2 parents ecdf310 + 1bf7b83 commit 072479b

File tree

5 files changed

+22
-0
lines changed

5 files changed

+22
-0
lines changed

src/Enum/DoctrineClass.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,9 @@ final class DoctrineClass
2525
* @var string
2626
*/
2727
public const ENTITY_REPOSITORY = 'Doctrine\ORM\EntityRepository';
28+
29+
/**
30+
* @var string
31+
*/
32+
public const CONNECTION = 'Doctrine\DBAL\Connection';
2833
}

src/Rules/Doctrine/RequireQueryBuilderOnRepositoryRule.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,10 @@ public function processNode(Node $node, Scope $scope): array
5252
return [];
5353
}
5454

55+
if ($callerType->isInstanceOf(DoctrineClass::CONNECTION)->yes()) {
56+
return [];
57+
}
58+
5559
$identifierRuleError = RuleErrorBuilder::message(self::ERROR_MESSAGE)
5660
->identifier(DoctrineRuleIdentifier::REQUIRE_QUERY_BUILDER_ON_REPOSITORY)
5761
->build();

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)