Skip to content

Commit 50bc942

Browse files
authored
add invokable controller (#242)
1 parent b330674 commit 50bc942

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

src/Rules/Symfony/NoControllerMethodInjectionRule.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ public function processNode(Node $node, Scope $scope): array
5353
continue;
5454
}
5555

56-
if ($classMethod->isMagic()) {
56+
// check invoke as well
57+
if ($classMethod->isMagic() && $classMethod->name->toString() !== '__invoke') {
5758
continue;
5859
}
5960

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanRules\Tests\Rules\Symfony\NoControllerMethodInjectionRule\Fixture;
6+
7+
use Symfony\Component\Routing\Annotation\Route;
8+
use Symplify\PHPStanRules\Tests\Rules\Symfony\NoControllerMethodInjectionRule\Source\SomeService;
9+
10+
final class InvokableActionInjectionController
11+
{
12+
/**
13+
* @Route("/some-action", name="some_action")
14+
*/
15+
public function __invoke(SomeService $someService)
16+
{
17+
}
18+
}

tests/Rules/Symfony/NoControllerMethodInjectionRule/NoControllerMethodInjectionRuleTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ public static function provideData(): Iterator
2929
15,
3030
]]];
3131

32+
yield [__DIR__ . '/Fixture/InvokableActionInjectionController.php', [[
33+
sprintf(NoControllerMethodInjectionRule::ERROR_MESSAGE, SomeService::class),
34+
15,
35+
]]];
36+
3237
yield [__DIR__ . '/Fixture/SkipRequestParameterController.php', []];
3338
yield [__DIR__ . '/Fixture/SkipScalarParameterController.php', []];
3439
}

0 commit comments

Comments
 (0)