Skip to content

Commit cdad4f5

Browse files
authored
[symfony] Skip NoListenerWithoutContractRule form listener (#196)
1 parent 51a358c commit cdad4f5

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

src/Enum/SymfonyClass.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ final class SymfonyClass
88
{
99
public const SECURITY_LISTENER = 'Symfony\Component\Security\Http\Firewall\AbstractListener';
1010

11+
public const FORM_SECURITY_LISTENER = 'Symfony\Component\Security\Http\Firewall\UsernamePasswordFormAuthenticationListener';
12+
1113
public const ROUTE_ATTRIBUTE = 'Symfony\Component\Routing\Attribute\Route';
1214

1315
/**

src/Rules/Symfony/NoListenerWithoutContractRule.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
namespace Symplify\PHPStanRules\Rules\Symfony;
66

7-
use PhpParser\Node\Name;
87
use PhpParser\Node;
8+
use PhpParser\Node\Name;
99
use PhpParser\Node\Stmt\Class_;
1010
use PHPStan\Analyser\Scope;
1111
use PHPStan\Node\InClassNode;
@@ -151,6 +151,6 @@ private function isSecurityListener(Class_ $class): bool
151151
return false;
152152
}
153153

154-
return $class->extends->toString() === SymfonyClass::SECURITY_LISTENER;
154+
return in_array($class->extends->toString(), [SymfonyClass::SECURITY_LISTENER, SymfonyClass::FORM_SECURITY_LISTENER], true);
155155
}
156156
}
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 SkipAnotherSecurityListener extends
6+
\Symfony\Component\Security\Http\Firewall\UsernamePasswordFormAuthenticationListener
7+
{
8+
9+
}

tests/Rules/Symfony/NoListenerWithoutContractRule/NoListenerWithoutContractRuleTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public function testRule(array $filePaths, array $expectedErrorsWithLines): void
2222
public static function provideData(): Iterator
2323
{
2424
yield [[__DIR__ . '/Fixture/SkipSecurityListener.php'], []];
25+
yield [[__DIR__ . '/Fixture/SkipAnotherSecurityListener.php'], []];
2526
yield [[__DIR__ . '/Fixture/SkipFormListener.php'], []];
2627

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

0 commit comments

Comments
 (0)