Haehnchen / idea-php-symfony2-plugin

IntelliJ IDEA / PhpStorm Symfony Plugin
https://plugins.jetbrains.com/plugin/7219
MIT License
913 stars 137 forks source link

PhpStorm inspection suppression causes erroneous Missing Route error #1573

Closed ProfM2 closed 2 years ago

ProfM2 commented 3 years ago

Separating the error suppression into its own block from the class DocBlock causes a Symfony Plugin Missing Route error.

Code like the following causes erroneous "Missing Route" fails:

<?php
/** @noinspection PhpUnused */

namespace App\Controller\Admin;

use ...

/**
 * Class DisconnectController
 * @package App\Controller\Admin
 * @Route("/admin/disconnect",
 *     name="admin_disconnect_")
 */
class DisconnectController extends AbstractController
{
    ... return $this->redirectToRoute('admin_deviceprofile_index'); // erroneously missing
}

Modifying the code to this works:

<?php

namespace App\Controller\Admin;

use ...

/**
 * Class DisconnectController
 * @package App\Controller\Admin
 * @Route("/admin/disconnect",
 *     name="admin_disconnect_")
 * @noinspection PhpUnused
 */
class DisconnectController extends AbstractController
{
    ... return $this->redirectToRoute('admin_deviceprofile_index'); // no problem
}
Haehnchen commented 3 years ago

@ProfM2 i need your method definitions. in general this feature is supported like this: https://github.com/Haehnchen/idea-php-symfony2-plugin/blob/d7ccdc637e6c90ded1c23733dd5c172d42f69597/src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/stubs/indexes/fixtures/RoutesStubIndex.php#L46

ProfM2 commented 3 years ago

I recently upgraded my project from 4.4.18 to 5.2.1, and I was able to recreate my issue. However, I may have initially copied the incorrect example. Here is my current code:

<?php
/** @noinspection PhpUnused */        <----- this inspection suppression causes the PhpStorm to think the
route is missing

namespace App\Controller\Admin;

use App\Datatables\DeviceProfileDatatable;
use App\Entity\Hardware\DeviceProfile;
use App\Form\Admin\DeviceProfileType;
use Exception;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
use Sg\DatatablesBundle\Datatable\DatatableFactory;
use Sg\DatatablesBundle\Response\DatatableResponse;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

/**
 * Class DeviceProfileController
 * @package App\Controller\Admin
 * @Route("/admin/deviceprofile",
 *     name="admin_deviceprofile_")
 * @noinspection PhpUnused                   <--------------  this inspection is fine and appears to work
normally, but isn't created here when you right-click and select suppress for entire file, it goes above,
where it causes the route to "go missing"
 */
class DeviceProfileController extends AbstractController
{
    /**
     * Lists all Device Profiles.
     *
     * @Route("/",
     *     name="index",
     *     methods={"GET"})
     * @param Request $request
     * @return Response
     */
    public function index(Request $request): Response
    { ... display the list of devices ... }

    /**
     * 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()) {
            $em = $this->getDoctrine()->getManager();
            $em->persist($profile);
            $em->flush();

            return $this->redirectToRoute('admin_deviceprofile_index');  // THIS IS THE ROUTE THAT "GOES MISSING"
        }

        return $this->render('admin/deviceprofile_detail.html.twig', [
            'profile' => $profile,
            'action' => 'create',
            'formProfile' => $formProfile->createView(),
        ]);
    }
    ...
}

I use 4 $this-redirectToRoute functions throughout this Controller, and all 4 "Go Missing" at the same time with the inspection location at the top

Haehnchen commented 2 years ago

i just copied this file inside phpstorm. there is no (or anymore) problem