deep-assoc-completion icon indicating copy to clipboard operation
deep-assoc-completion copied to clipboard

How to setup for array associated with object?

Open dexcell opened this issue 4 years ago • 2 comments

Hi,

I have a var called $app, its a class \Silex\Application that implements ArrayAccess.

then inside that $app array there is twig key which is an object of \Twig\Environment So in source code i use it like this

$app['twig']->render('stuff');

How to enable auto completion for $app['twig'] to show render function? How to setup this in .phpstorm.meta.php?

Thanks

dexcell avatar Feb 16 '22 00:02 dexcell

Hi. ArrayAccess completion is not supported. See https://github.com/klesun/deep-assoc-completion/issues/102

Need a PR or something for this feature.

klesun avatar Feb 16 '22 08:02 klesun

You could possibly trick the plugin into thinking that $app is an associative array by doing something like this:

/** @var $app = ['twig' => new \Twig\Environment()] */
$app = new \Silex\Application();

The plugin will consider $app type a union of associative array and class instance in such case if I remember right how it works.

This PSALM annotation should probably work as well:

/** @var \Silex\Application|array{twig: \Twig\Environment} $app */
$app = something();

klesun avatar Feb 16 '22 08:02 klesun