Phpstorm Intellisense / Code completion for inherited properties

久未见 提交于 2019-12-11 02:11:53

问题


I have a problem with Phpstorm's code completion for inherited properties. There is an example from my code below.

class ParentClass
{
  public $repository;
}

/*
 * @property Entity\SubClassRepository $repository
 */
class SubClass extends ParentClass
{
  public function __construct()
  {
    $this->repository= $this->em->getRepository('Entity\Subclass');
  }

  public function ExampleFunction()
  {
    $this->repository-> !Here i need the code completion!
  }
}

The getRepository function returns SubClassRepository for param = Entity\SubClass or returns OtherClassRepository for param = Entity\OtherClass. Btw there is no exact type that it returns. Thus; i need to say Phpstorm what type $repository object of parent class is.

I know that Phpstorm uses Phpdoc notation for code completion. Thus i tried to use @property notation and added the lines below to SubClass.

/*
 * @property Entity\SubClassRepository $repository
 */

It doesn't work. Do you have any idea? Thanks much.


回答1:


The problem was about my missing * character in annotations as @LazyOne said in his comment. @property tag is working perfect now.

It should read:

/**
 * @property Entity\SubClassRepository $repository
 */


来源:https://stackoverflow.com/questions/14663336/phpstorm-intellisense-code-completion-for-inherited-properties

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!