PhpStorm does not recognize Doctrine object classes

PhpStorm does not seem to recognize any of my Doctrine entity classes or their methods.

$comment = $em->getRepository('MyBundle:Comment')->findOneBy(array('id' => $id)); $comment->getId(); /* PHPSTORM THROWS WARNING: Method getId() not found in subject class */ 

The error disappears only when I explicitly comment on it - which really clutters my controller.

 /* @var \MyBundle\Entity\Comment $comment */ $comment = $em->getRepository('MyBundle:Comment')->findOneBy(array('id' => $id)); 

Is there a way to document this for PhpStorm in my entity class?

I am using the Symfony2 plugin with PhpStorm 8. Thank you!

+8
source share
4 answers

I had this problem. The magic solution by clearing the Doctrine metadata:

 php app/console doctrine:cache:clear-metadata 

EDIT: The symfony plugin's GitHub repository has a brief description of what to do when this problem occurs:

https://github.com/Haehnchen/idea-php-symfony2-plugin

Autofill (or something else) does not work! Help!

[...]

Many functions require app / cache / dev / appDevDebugProjectContainer.xml to exist. this is created when you load your application in a dev environment (open / app_dev.php in a browser or php app / console application).

Since my server is deleted by manually syncing the app/cache/dev/appDevDebugProjectContainer.xml , I solved my problem.

When I was working on the local server, instead, the command I wrote above helped me perform auto-completion again.

+9
source

I have the same problem with the Symfony2 plugin, this may not be a very good solution, but it works

 /** @var EntityManager $em */ $em = $this->doctrine->getManager(); 
+6
source

Your problem should be fixed. There was a problem with several implementations of getRepository proxy classes in the cache folder. just upgrade to> = 0.11.81

+1
source

Now I prefer to declare repositories as services so that you don’t have such typing problems:

 services: MyBundle\Entity\CommentRepository: class: MyBundle\Entity\CommentRepository public: true factory: ['@doctrine', getRepository] arguments: - MyBundle\Entity\Comment 

Then in your controller:

 use MyBundle\Entity\CommentRepository; $comment = $this->get(CommentRepository::class)->findOneBy(['id' => $id]); 
+1
source

Source: https://habr.com/ru/post/979416/


All Articles