自动完成动态声明的方法(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.
更多推荐
发布评论