PhpStorm doesn't 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 goes away, only when I explicitly comment 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'm using the Symfony2 plugin with PhpStorm 8. Thanks!
I have the same problem with the Symfony2 Plugin, this is maybe not a nice solution but it works
/** @var EntityManager $em */
$em = $this->doctrine->getManager();
your issue should be fixed, now. there was a problem on multiple getRepository
implementations of proxy classes in cache folder. just update to >= 0.11.81
Now, I prefer declaring repositories as services so you don't have those typehint 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]);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With