idea-php-symfony2-plugin icon indicating copy to clipboard operation
idea-php-symfony2-plugin copied to clipboard

Proper doctrine repository autocompletion support

Open apfelbox opened this issue 6 years ago • 2 comments

Hi!

First up: thanks for your great plugin. 🙌

I noticed that the completion for doctrine repositories is super weird and seems to just be name-based.

Doesn't work ❌

(method name anything other than getRepository())

public function doSth ()
{
    $this->a()->createQueryBuilder("test")
        ->select("te")
}


protected function a () : EntityRepository
{
    return $this->doctrine->getRepository(TestEntity::class);
}

Doesn't work ❌

(method name getRepository(), but no argument)

public function doSth ()
{
    $this->getRepository()->createQueryBuilder("test")
        ->select("te")
}


protected function getRepository () : EntityRepository
{
    return $this->doctrine->getRepository(TestEntity::class);
}

Works... 🤔

(method name getRepository() and unused and obsolete argument)

public function doSth ()
{
    $this->getRepository(TestEntity::class)->createQueryBuilder("test")
        ->select("te")
}

//                               \/ empty
protected function getRepository () : EntityRepository
{
    return $this->doctrine->getRepository(TestEntity::class);
}

The last case seems weird, as we are basically just passing in an unused argument, but that triggers the autocompletion.

It would be great to have proper tracing, so that every call to Symfony\Bridge\Doctrine\RegistryInterface::getRepository() is correctly recognized, and this type is properly propagated throughout the app (basically examples 1 and 2 above).

In the meantime: is there a way to build a generic Model class, that somehow typehints what repository it uses inside? Or do I really need to always use the exact name getRepository() and always pass the FQCN as argument?

Thanks for your great work!

apfelbox avatar Mar 27 '19 13:03 apfelbox

Feel free to link related issues to this one. If I see that correctly, there appears quite a few of them.

Would make sense to use a single issue that groups them all up.

apfelbox avatar Mar 27 '19 13:03 apfelbox

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

arolznov avatar Sep 04 '20 10:09 arolznov