I have a symfony 3.4 project in PhpStorm 2020.2. I import the following annotations
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
and use them, for example here:
/** @Route("/feedback/delete/{id}", name="feedbackDelete") @Method("DELETE") */
and
/** @Route("/dashboard", name="dashboard") @Template() */
Now PhpStorm tells me Import 'Sensio\Bundle\FrameworkExtraBundle\Configuration\Method' is never used - same for Template. That is not true, but why does PhpStorm not recognize it?
I use the plugins PHP Annotations 7.1.3 and Symfony Support 0.21.202.
It's annoying because it always shows up in code analyses and I can't auto-optimize imports, because it breaks the code.
I thought, why bothering to ask - symfony 3.4 is old and I will probably soon migrate to symfony 5.X. But migration is a headache and since I recently talked with someone from a big symfony project where they still use 2.*, I thought there might actually be more people with this problem.
After experimenting a bit, I found the problem:
The PhpStorm plugin PHP Annotations does recognize the annotation, if it is starting in a new line of the PhpDoc. So while @Template is not recognized as used here:
/** @Route("/dashboard", name="dashboard") @Template() */
it works, if I change it to
/**
* @Route("/dashboard", name="dashboard")
* @Template()
*/
or even this is enough:
/** @Route("/dashboard", name="dashboard")
* @Template() */
I don't really like that since I like to keep my line count low and I don't see any advantage of putting this small annotation in a new line, but at least now I have a work-around.
I also opened an issue for this which can be found here: https://github.com/Haehnchen/idea-php-annotation-plugin/issues/211