Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to setup for array associated with object? #199

Open
dexcell opened this issue Feb 16, 2022 · 2 comments
Open

How to setup for array associated with object? #199

dexcell opened this issue Feb 16, 2022 · 2 comments

Comments

@dexcell
Copy link

dexcell commented Feb 16, 2022

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
Copy link
Owner

klesun commented Feb 16, 2022

Hi. ArrayAccess completion is not supported.
See #102

Need a PR or something for this feature.

@klesun
Copy link
Owner

klesun commented Feb 16, 2022

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants