Skip to content

Commit 487e8cd

Browse files
committed
next rule
1 parent 349b888 commit 487e8cd

File tree

3 files changed

+54
-7
lines changed

3 files changed

+54
-7
lines changed

README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1327,6 +1327,59 @@ class SomeListener implements EventSubscriberInterface
13271327

13281328
:+1:
13291329

1330+
<br>
1331+
1332+
### NoStringInGetSubscribedEventsRule
1333+
1334+
Symfony getSubscribedEvents() method must contain only event class references, no strings
1335+
1336+
```yaml
1337+
rules:
1338+
- Symplify\PHPStanRules\Rules\Symfony\NoStringInGetSubscribedEventsRule
1339+
```
1340+
1341+
```php
1342+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1343+
1344+
class SomeListener implements EventSubscriberInterface
1345+
{
1346+
public static function getSubscribedEvents(): array
1347+
{
1348+
return [
1349+
'event' => 'onEvent',
1350+
];
1351+
}
1352+
1353+
public function onEvent()
1354+
{
1355+
}
1356+
}
1357+
```
1358+
1359+
:x:
1360+
1361+
<br>
1362+
1363+
```php
1364+
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
1365+
1366+
class SomeListener implements EventSubscriberInterface
1367+
{
1368+
public static function getSubscribedEvents(): array
1369+
{
1370+
return [
1371+
Event::class => 'onEvent',
1372+
];
1373+
}
1374+
1375+
public function onEvent()
1376+
{
1377+
}
1378+
}
1379+
```
1380+
1381+
:+1:
1382+
13301383

13311384

13321385

src/Enum/ClassName.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,6 @@ final class ClassName
7070
* @var string
7171
*/
7272
public const DOCTRINE_FIXTURE_INTERFACE = 'Doctrine\Common\DataFixtures\FixtureInterface';
73-
7473
/**
7574
* @var string
7675
*/

src/Rules/Symfony/NoStringInGetSubscribedEventsRule.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,6 @@
2222
*/
2323
final class NoStringInGetSubscribedEventsRule implements Rule
2424
{
25-
/**
26-
* @var string
27-
*/
28-
private const EVENT_SUBSCRIBER_INTERFACE = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
29-
3025
/**
3126
* @var string
3227
*/
@@ -56,7 +51,7 @@ public function processNode(Node $node, Scope $scope): array
5651
}
5752

5853
// only handle symfony one
59-
if (! $classReflection->implementsInterface(self::EVENT_SUBSCRIBER_INTERFACE)) {
54+
if (! $classReflection->implementsInterface(ClassName::EVENT_SUBSCRIBER_INTERFACE)) {
6055
return [];
6156
}
6257

0 commit comments

Comments
 (0)