PhpStorm:标注为继承方法的返回类型? [英] PhpStorm: annotation for inherited method return type?

查看:1051
本文介绍了PhpStorm:标注为继承方法的返回类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用贝哈特子上下文类我需要调用从主背景,例如方法 $这个 - > getMainContext() - GT; foobar的()。 PhpStorm相当合理警告我说, foobar的()不存在,因为它需要 getMainContext()返回一个 ExtendedContextInterface ,不是我的具体 FeatureContext

Using a Behat sub-context class I need to call a method from the main context, e.g. $this->getMainContext()->fooBar(). PhpStorm quite reasonably warns me that fooBar() doesn't exist, because it expects getMainContext() to return an ExtendedContextInterface, not my concrete FeatureContext.

有没有办法来标注我的子类来告诉PhpStorm的 getMainContext()实际上返回我的具体类?

Is there a way to annotate my sub-class to tell PhpStorm that getMainContext() actually returns my concrete class?

一个解决方案是重写 getMainContext()只是有在其上添加自己的PHPDoc的方法,从而指定不同的返回类型,但添加的方法只是得到更好的code意义上的IDE是可怕的。

One solution is to override getMainContext() just to have a method on which to add my own PHPDoc, thus specifying a different return type, but adding a method just to get nicer code sense in an IDE is horrid.

顺便说一句,我知道这一切有点哈克和理论上我的子方面不应该依赖于具有特定的具体实现我的主要方面;在现实中,虽然贝哈特,并不意味着实际的。

BTW, I know this is all a bit hacky and that theoretically my sub-context shouldn't depend upon my main context having a particular concrete implementation; in reality though Behat doesn't make that practical.

推荐答案

使用标准@method标注为类作品:

Using the standard @method annotation for the class works:

 /**
  * @method FeatureContext getMainContext()
  */
 class SubContext extends BehatContext
 {
     public function foo()
     {
          $this->getMainContext()->bar();
     }
 }

这篇关于PhpStorm:标注为继承方法的返回类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆