Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to make PhpStorm's autocomplete "go deeper"?

In PhpStorm, if I create an object, then I have all auto complete on that object working fine:

$object = new MyClass();
$object->getNa...

Will auto complete to

$object->getName();

So far so good, but if I get returned an object through the first method, then the auto complete will not work on that.

$car->getDriver()->getNam...

Will show an empty list. The getDriver method has its PHPDoc @return tag set to 'Driver' though and in some other IDEs, this therefore works to get the correct auto complete.

Wondering if there's a setting that I missed somewhere or if PhpStorm doesn't offer this kind of advanced auto complete yet?

like image 768
Khepin Avatar asked Oct 01 '11 10:10

Khepin


1 Answers

The function getDriver() needs appropriate type-hints for the return value (function's docblock):

  * @return classOrInterfaceName

This is normally enough to have a IDE "go deeper". I'm pretty sure Phpstorm supports that, but I'm not a Phpstorm user.

Take care the file with the interface/class is within the project or referenced to it.

As a work around you can assign the return value to a variable and type-hint that variable. Might not be that comfortable but can help.

like image 80
hakre Avatar answered Oct 20 '22 00:10

hakre