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

Container does not take has() into account #173

Open
wouterj opened this issue Apr 24, 2021 · 0 comments
Open

Container does not take has() into account #173

wouterj opened this issue Apr 24, 2021 · 0 comments
Labels
enhancement New feature or request

Comments

@wouterj
Copy link
Contributor

wouterj commented Apr 24, 2021

I have the following (rather ugly, but required) code:

        if ($this->container->has('wouterj_eloquent.initializer')) {
            $this->container->get('wouterj_eloquent.initializer')->initialize();
        }

This produces the following error with Psalm level 3 and this plugin (both latest version):

ERROR: PossiblyNullReference - src/WouterJEloquentBundle.php:44:68 - Cannot call method initialize on possibly null value (see https://psalm.dev/083)
            $this->container->get('wouterj_eloquent.initializer')->initialize();

I would expect this plugin to somehow take the has() call into account (and thus removing null from the union return type of get()). I tried digging into the source code to contribute a fix, but I'm a bit unsure how to maintain some sort of global state that is reset after the if statement is left.

@seferov seferov added the enhancement New feature or request label Aug 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants