自动完成动态声明的方法(Autocomplete dynamic declared method)

编程入门 行业动态 更新时间:2024-10-23 15:30:55
自动完成动态声明的方法(Autocomplete dynamic declared method)

如何让我的IDE注册此方法返回参数的实例?

所以我可以这样做:

Class::models()->getModel('newModel')->newModelMethodHere()?

代码有效,但不是PHPStorm中的自动完成。

/** * Returns the object of the model * * @var $this->_models[$model] $model * @param string object $model * @throws Exception * @return object */ public function getModel($model) { if (array_key_exists($model, $this->_models) && class_exists($model) && is_object($this->_models[$model]) && $this->_models[$model] instanceof $model) { if (is_a($this->_models[$model], $model)) { /* @var $this->_models[$model] $model */ return ($this->_models[$model]); } } throw new Exception('Model ' . (string)$model . ' is not registered correctly.'); }

How do I get my IDE to register that this method is returning a instance of the parameter?

So I could do something like this:

Class::models()->getModel('newModel')->newModelMethodHere()?

The code works, but not the autocomplete in PHPStorm.

/** * Returns the object of the model * * @var $this->_models[$model] $model * @param string object $model * @throws Exception * @return object */ public function getModel($model) { if (array_key_exists($model, $this->_models) && class_exists($model) && is_object($this->_models[$model]) && $this->_models[$model] instanceof $model) { if (is_a($this->_models[$model], $model)) { /* @var $this->_models[$model] $model */ return ($this->_models[$model]); } } throw new Exception('Model ' . (string)$model . ' is not registered correctly.'); }

最满意答案

你应该修改你的评论块。 返回应该澄清什么对象返回。

/** * Returns the object of the model * ... * @return ModelNameClass */

I had to change my code a bit, but I managed to get this to work:

namespace PHPSTORM_META { $STATIC_METHOD_TYPES = array( \ClassName::getModel('') => [ "" == "@", ], ); }

in a new .phpstorm.meta.php file in the root of my project in PHPStorm.

更多推荐

本文发布于:2023-08-06 05:02:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1444571.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自动完成   声明   方法   动态   method

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!