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

QueryBuilder has no autocompletion for arguments when getting the Repository from an Entity Service

Open jhard opened this issue 5 years ago • 0 comments

Say I have the following Service + Repository (the MyEntityRepository is annotated as the RepositoryClass in the Entity)

class MyEntityRepository extends ServiceEntityRepository
{
   public function __construct(ManagerRegistry $registry)
   {
      parent::__construct($registry, MyEntity::class);
   }
}
class MyEntityService
{
   private $entityManager;

   public function __construct(EntityManagerInterface $em)
   {
      $this->entityManager    = $em;
   }
   
   public function getRepository() : MyEntityRepository
   {
      return $this->entityManager->getRepository(MyEntity::class);
   }
}

If if use $myEntityService->getRepository()->createQueryBuilder("m")->andWhere("m."), I won't have auto-complete for the entity properties. If I get the Repository by other means (e.g. $entityManager->getRepository(MyEntity::class)), it works fine A hint to what's happening is that the suggested alias for the query builder isn't "me" or "my_entity" but "mes" or "my_entity_service.get". Even if I explicitly type-hint it, e.g.

/** @var MyEntityRepository $repo */
$repo = $myEntityService->getRepository();
$repo->createQueryBuilder("m")->andWhere("m.")

I get the same result. PHPStorm will tell me that MyEntityRepository is already inferred from the code, and hovering over $repo will confirm as much. Method chaining does work, only the arguments get no auto-suggest support.

Using PHPSTORM_META as I mentioned in https://github.com/Haehnchen/idea-php-symfony2-plugin/issues/1483#issuecomment-716051366 doesn't help either.

Is there any way to make this work? What can I do to provide more information for debugging?

I'm on 2020.3 (Plugin Version 0.21.203), but I believe this wasn't working on 2020.2 either.

PhpStorm 2020.3 Build #PS-203.5981.175, built on December 2, 2020 Runtime version: 11.0.9+11-b1145.21 amd64 VM: OpenJDK 64-Bit Server VM by JetBrains s.r.o. Linux 5.4.0-54-generic GC: ParNew, ConcurrentMarkSweep Memory: 3959M Cores: 24 Registry: run.processes.with.pty=TRUE Non-Bundled Plugins: A move tab left and right using the keyboard plugin - by momomo.com, com.jan.evendarker, com.jetbrains.fast.mouse.scroll, rocks.blackcat.vcl, com.perl5, com.intellij.plugins.html.instantEditing, lv.midiana.misc.phpstorm-plugins.deep-keys, de.espend.idea.php.toolbox, de.espend.idea.php.annotation, fr.adrienbrault.idea.symfony2plugin, ru.adelf.idea.dotenv Current Desktop: KDE

jhard avatar Dec 05 '20 09:12 jhard