PhpStorm auto-complete support for unknown object properties managed by Pimple?

932 views Asked by At

I have the following code in an application powered by Silex:

$uknownObj->unkownRef

$uknownObj being a dependency injection container.

I know that unkownRef is of instance MyCoolObj.

Now how can I tell IntelliJ / PhpStorm to actually help me with autocomplete of this said object?

4

There are 4 answers

2
Alex Blex On

You can either use phpdoc comments as suggested by xmoex, or assert type with instanceof:

enter image description here

3
mansoor.khan On

Simply assign unkownRef to a variable and provide annotation like this.

/** @var MyCoolObj $obj */
$obj = $uknownObj->unkownRef;
1
Yoann Kergall On

You can use phpdoc in container class, this is what i use with Slim framework :

/**
* @property-read \Monolog\Logger logger
* @property-read \Slim\Views\Twig view
* @property-read \PDO db
*/
class Container extends PimpleContainer implements ContainerInterface
{
}
0
Shaharia Azam On

I just solved this by creating just _ide_autocomplete.php file in the project root where I just created a dummy class with all the slim container key as property. Then in my routes, in the beginning I just put a phpblock like this

/** @var Dummy $this */

My source codes are articles are in https://blog.shaharia.com/slim-php-framework-phpstorm-ide-autocompletion-solution/