0
votes

I have a rather large Symfony 4.4 project that I recently reopened. Going through the code with PhpStorm 2020.3, adding some new functionality and code cleanup.

I get to a couple of Controllers and I'm getting a "Missing Route" error in PhpStorm. However, the routes do exist when I run php bin/console debug:router.

Is there a cache that I haven't cleared to cause PhpStorm to rescan routes?

Output from: php bin/console debug:router

admin_deviceprofile_index GET ANY ANY /admin/deviceprofile/
admin_deviceprofile_show GET ANY ANY /admin/deviceprofile/{deviceprofile_id}/show
admin_deviceprofile_create GET|POST ANY ANY /admin/deviceprofile/create
admin_deviceprofile_edit GET|POST ANY ANY /admin/deviceprofile/{deviceprofile_id}/edit
admin_deviceprofile_delete DELETE ANY ANY /admin/deviceprofile/{deviceprofile_id}/delete

My snippet of the Controller ...

/**
 * @Route("/admin/deviceprofile",
 *     name="admin_deviceprofile_")
 */
class DeviceProfileController extends AbstractController
{
    /**
     * Lists all Device Profiles.
     * @Route("/",
     *     name="index",
     *     methods={"GET"})
     * @param Request $request
     * @return Response
     */
    public function index(Request $request): Response
    { ... }

    /**
     * Creates a new Device Profile entity.
     * @Route("/create",
     *     name="create",
     *     methods={"GET", "POST"})
     * @param Request $request
     * @return Response
     */
    public function create(Request $request): Response
    {
        $profile = new DeviceProfile();
        $formProfile = $this->createForm(DeviceProfileType::class, $profile);
        $formProfile->handleRequest($request);

        if ($formProfile->isSubmitted() && $formProfile->isValid()) {
            ...
            return $this->redirectToRoute('admin_deviceprofile_index');
        }

        return $this->render(...);
    }
}

PhpStorm claims the 'admin_deviceprofile_index' is Missing. However, it is not. Also, this same pattern of having a route for the controller is used elsewhere, yet those routes are fine, the problem appears in just a couple of Controllers.

Also, through debugging this 'problem', I moved the controller route partials to the functions themselves, and PhpStorm still did not see the routes properly.

I have also ran php bin/console cache:clear and have done the PhpStorm: File > Invalidate Caches / Restart to no avail.

Anything I could try to clear this up? I loathe seeing "errors" in the code inspection.

1
Such Symfony specific functionality is provided by the Symfony Support plugin. Maybe check their Issue Tracker. P.S. I'm not a Symfony user so not sure what exactly is required .. but since that path is declared via @Route -- do you have PHP Annotations plugin installed? It is the one that handles such annotations (maybe it's needed here as well). - LazyOne

1 Answers

0
votes

Figured out that if you have a PhpStorm @noinspection tag block and a class-level docblock, it will conflict causing the erroneous "Missing Route" message.

Github issue here