Search code examples
phpstorm

Code completion, insert use operator (namespace) with right click on undefined class


When I type

class MyController extends Controller

and I forget to choose the class from code completion, and then PhpStorm show me "Undefined class Response"; there is no way to add it, after I have written, using right click on the word "Controller" to get this line inserted automatically?

use Symfony\Bundle\FrameworkBundle\Controller\Controller;

Why I need delete "Controller", type again and select from the list of classes?


Solution

  • Why I need delete "Controller", type again and select from the list of classes?

    It's a wrong place to ask for explanation for your own actions.


    In any case:

    1. Place caret on that place where IDE tells you "Undefined class XXX"
    2. Bring the Quick Fix / Intentions menu -- Alt + Enter or via light bulb icon
    3. Choose the appropriate menu entry -- it will be Import class
    4. If there will be more than one choice -- IDE will show you the list of classes to choose from

    enter image description here