Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: How to enable autocompletion for annotations in PHPStorm?

Following this simple code:

namespace AppBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;


class TestController extends Controller
{
    /**
     * @param $value
     * @return Response
     */
    public function indexAction($value)
    {
        return new Response('Hello:' . $value);
    }
}

Is any possibility to have code completion when I would like to add @Route in phpDoc? When I type @Route it should show code completion and automatic add "use" statement? I watched a symfony tutorial (I'm beginner) and in this video PHPStrom showed code completion and automatic added "use" statement... I installed symfony plugin and other things and code completions works.

like image 427
Mati Avatar asked Mar 26 '16 18:03

Mati


People also ask

How to autocomplete routes in PhpStorm using Symfony?

PHPStorm uses the appDevUrlGenerator.php located in the dev cache folder to autocomplete routes. Check it to make sure symfony generates correct route names. #Settings > Other settings > Symfony plugin - Path to urlGenerator.php Check it's contents.

How do I enable Symfony plugin with autoconfiguration?

Click the Enable the Symfony plugin with autoconfiguration link in the notification message. In the Settings/Preferences dialog ( Ctrl+Alt+S ), navigate to PHP | Symfony and select the Enable Plugin for this Project checkbox.

What is PhpStorm Symfony?

PhpStorm provides coding assistance and navigation facilities for developing applications with the Symfony framework. Symfony support is provided by means of the Symfony Plugin. The source code for the plugin, as well as its issue tracker, can be found on GitHub.

What settings should I change under PHP | Symfony?

Depending on how the Symfony project is structured, you may have to change some additional settings under PHP | Symfony. When working with a Symfony application that follows the structure generated by, for example, the symfony/framework-standard-edition Composer project, the default paths and settings will work fine.


1 Answers

As correctly stated by Patrik Karisch in the question's comments:

You need the to install the PHP Annotations Plugin to enable:

  • autocompletion
  • automatic addition of use-statements

... and other helpers for annotations in PHPStorm.

Installation:

  • Go To Preferences > Plugins -> Browse Repositories
  • Enter "Annotation" into the Search box
  • Locate the PHP Annotations Plugin in the Result List
  • Click Install
  • Restart PHPStorm to enable the plugin
like image 86
Nicolai Fröhlich Avatar answered Oct 05 '22 20:10

Nicolai Fröhlich