Skip to content

Commit cfdb0d3

Browse files
authored
Add FQN route annotaiton support (#161)
1 parent 7d3dee9 commit cfdb0d3

File tree

4 files changed

+33
-0
lines changed

4 files changed

+33
-0
lines changed

rector.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
'*/Source/*',
1616
'*/Fixture/*',
1717
StringClassNameToClassConstantRector::class => [
18+
__DIR__ . '/src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php',
1819
__DIR__ . '/tests/Naming/ClassToSuffixResolverTest.php',
1920
__DIR__ . '/tests/Rules/Rector/PhpUpgradeImplementsMinPhpVersionInterfaceRule/PhpUpgradeImplementsMinPhpVersionInterfaceRuleTest.php',
2021
],

src/Symfony/NodeAnalyzer/SymfonyControllerAnalyzer.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public static function isControllerActionMethod(ClassMethod $classMethod): bool
5353
return false;
5454
}
5555

56+
if (str_contains($docComment->getText(), 'Symfony\Component\Routing\Annotation\Route')) {
57+
return true;
58+
}
59+
5660
return \str_contains($docComment->getText(), '@Route');
5761
}
5862
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Symfony\RequireInvokableControllerRule\Fixture;
6+
7+
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
8+
9+
final class MultipleMethodsController extends AbstractController
10+
{
11+
/**
12+
* @\Symfony\Component\Routing\Annotation\Route()
13+
*/
14+
public function run()
15+
{
16+
}
17+
18+
/**
19+
* @\Symfony\Component\Routing\Annotation\Route()
20+
*/
21+
public function go()
22+
{
23+
}
24+
}

tests/Rules/Symfony/RequireInvokableControllerRule/RequireInvokableControllerRuleTest.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public static function provideData(): Iterator
2727
yield [__DIR__ . '/Fixture/SkipRandomPublicMethodController.php', []];
2828

2929
yield [__DIR__ . '/Fixture/MissnamedController.php', [[RequireInvokableControllerRule::ERROR_MESSAGE, 14]]];
30+
yield [__DIR__ . '/Fixture/MultipleMethodsController.php', [
31+
[RequireInvokableControllerRule::ERROR_MESSAGE, 14],
32+
[RequireInvokableControllerRule::ERROR_MESSAGE, 21],
33+
]];
3034
}
3135

3236
/**

0 commit comments

Comments
 (0)