Skip to content

Commit c052ff5

Browse files
committed
[symfony] Skip symfony security in NoListenerWithoutContractRule
1 parent a72c3ba commit c052ff5

File tree

4 files changed

+25
-0
lines changed

4 files changed

+25
-0
lines changed

src/Enum/SymfonyClass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
final class SymfonyClass
88
{
9+
public const SECURITY_LISTENER = 'Symfony\Component\Security\Http\Firewall\AbstractListener';
10+
911
public const ROUTE_ATTRIBUTE = 'Symfony\Component\Routing\Attribute\Route';
1012

1113
/**

src/Rules/Symfony/NoListenerWithoutContractRule.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,10 @@ public function processNode(Node $node, Scope $scope): array
7979
return [];
8080
}
8181

82+
if ($this->isSecurityListener($classLike)) {
83+
return [];
84+
}
85+
8286
if ($this->hasAsListenerAttribute($classLike)) {
8387
return [];
8488
}
@@ -141,4 +145,13 @@ private function isFormEventsListener(Class_ $class): bool
141145

142146
return false;
143147
}
148+
149+
private function isSecurityListener(Class_ $class): bool
150+
{
151+
if (! $class->extends instanceof Node\Name) {
152+
return false;
153+
}
154+
155+
return $class->extends->toString() === SymfonyClass::SECURITY_LISTENER;
156+
}
144157
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
namespace Symplify\PHPStanRules\Tests\Rules\Symfony\NoListenerWithoutContractRule\Fixture;
4+
5+
final class SkipSecurityListener extends
6+
\Symfony\Component\Security\Http\Firewall\AbstractListener
7+
{
8+
9+
}

tests/Rules/Symfony/NoListenerWithoutContractRule/NoListenerWithoutContractRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ public function testRule(array $filePaths, array $expectedErrorsWithLines): void
2121

2222
public static function provideData(): Iterator
2323
{
24+
yield [[__DIR__ . '/Fixture/SkipSecurityListener.php'], []];
2425
yield [[__DIR__ . '/Fixture/SkipFormListener.php'], []];
2526

2627
yield [[__DIR__ . '/Fixture/SomeContractedListener.php'], []];

0 commit comments

Comments
 (0)