#[Route] attribute on invocable controller cannot be found
For the most part, this plugin works great. But I noticed in a project that a select few routes kept showing up as missing according to the plugin:
The only thing that all these missing routes have in common, is that they are specified (as attributes) on a class level rather than a method level, e.g.:
<?php declare(strict_types=1);
namespace Foo;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
#[Route(path: '/bar', name: 'bar')]
class Bar
{
public function __invoke(Request $request): Response
{
return new Response();
}
}
PHPStorm version 2023.1 and also 2023.2 EAP Plugin version 2022.1.250
I got the same issue with the class level php attributes. For PhpDock annotations it seems to work, at least in an older project of mine I have no issues.
PHPStorm version 2023.2 Plugin version 2022.1.258
I can confirm that if I move the annotation to the method level (__invoke() in the example) that the route is recognized and no longer triggers a 'missing route' hint.
I have the same problem. I upgraded a small project from an old symfony version (4.4) to 7.0 and converted the annotations to attributes. I went to the same point with @alcohol (moving the attribute to the method level) to make it working.
That add precision, this was not an issue when using annotations on the class level on invokable controllers. This only happens when using attributes on the class level.
In the official Symfony documentation, the route attribute is placed on class level in invokable controllers : https://symfony.com/doc/current/controller/service.html#invokable-controllers