问题描述
我对继承的属性的Phpstorm代码完成有疑问.下面是我的代码中的一个示例.
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!
}
}
getRepository函数为param = Entity \ SubClass返回SubClassRepository或为param = Entity \ OtherClass返回OtherClassRepository.顺便说一句,它没有返回的确切类型.因此;我需要说Phpstorm父类的$ repository对象是什么类型.
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.
我知道Phpstorm使用Phpdoc表示法来完成代码.因此,我尝试使用@property表示法,并将下面的行添加到SubClass.
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.
推荐答案
问题出在我的注解中缺少我的*字符,如@LazyOne在其评论中所说. @property标签现在可以正常使用了.
The problem was about my missing * character in annotations as @LazyOne said in his comment. @property tag is working perfect now.
它应显示为:
/**
* @property Entity\SubClassRepository $repository
*/
这篇关于Phpstorm Intellisense/继承属性的代码完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!