D
D
DollyPapper2021-11-02 21:33:22
phpstorm
DollyPapper, 2021-11-02 21:33:22

PhpStorm autocomplete dynamic types?

Hello.
There is this code

$parentModel = $this->getDataSource()->getModel()->chainedParentObject();

The trouble is that phpstorm can't suggest methods because it can't determine the return type. Or rather, maybe, but not completely.
For example $this->getDataSource() will return an object that implements the DataSourceInterface which has some methods, but the classes that implement this interface also add their own. Naturally, you cannot specify that getDataSource() returns a specific type. And so on down the chain.
getModel() returns subclasses of ActiveRecord (Yii), but chainedParentObject() is a subclass of AR and naturally has an extra. methods and when set getModel()-> autocomplete prompts only AR methods. I understand that it is most likely impossible to define a dynamic type, but maybe there is still some kind of trick?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
sl0, 2021-11-03
@sl0

You can do this $dataSource = $this->getDataSource();
And set $dataSource to php doc.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question