klesun / deep-assoc-completion

A phpstorm plugin for associative array key typing and completion
Other
267 stars 17 forks source link

How to setup for array associated with object? #199

Open dexcell opened 2 years ago

dexcell commented 2 years ago

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

klesun commented 2 years ago

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 commented 2 years ago

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();