Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PhpStorm 2019.2 unused element in Symfony controller

I am using PhpStorm 2019.2 In the Symfony controller, methods are highlighted as not being used. Xdebug, then I get an error

I read on https://youtrack.jetbrains.com that this is possibly a bug, the new version of the IDE does not work correctly with annotations

C:\OpenServer\OSPanel\modules\php\PHP_7.2\php.exe -dxdebug.remote_enable=1 -dxdebug.remote_mode=req -dxdebug.remote_port=9090 -dxdebug.remote_host=127.0.0.1 C:\OpenServer\OSPanel\domains\myblog.loc\src\Controller\IndexController.php

Fatal error: Class 'Symfony\Bundle\FrameworkBundle\Controller\Controller' not found in C:\OpenServer\OSPanel\domains\myblog.loc\src\Controller\IndexController.php on line 18

Call Stack:
    0.0679     382496   1. {main}() C:\OpenServer\OSPanel\domains\myblog.loc\src\Controller\IndexController.php:0

Dump $_SERVER
   $_SERVER['REMOTE_ADDR'] is undefined
   $_SERVER['REQUEST_METHOD'] is undefined
Dump $_SESSION
   $_SESSION['*'] is undefined
Dump $_REQUEST

Process finished with exit code 255

Some Controller

class ContactController extends Controller
{
    /**
     * @Route("/contact", name="contact_view")
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function contactView()
    {
        return $this->render('contact/contact.html.twig', [

        ]);
    }
}

At the moment, the class and its action are marked as unused in the controller, what should I do?

like image 857
vevovip Avatar asked Aug 10 '19 05:08

vevovip


1 Answers

You can add your controllers and their actions as entry points. This way, those classes and methods will not be reported as dead code.

If your controllers are in src/Controller and your action methods have the -Action suffix, you can add these two rules as entry points in Settings| Editor | Inspections:

Class                    Member
/Controller/*Controller  *Action
/Controller/*Controller

enter image description here

like image 71
Lg102 Avatar answered Oct 03 '22 02:10

Lg102