Closed jordisala1991 closed 3 years ago
I'm not sure what's wrong, but try taking advantage of the advanced analysis where PHPStan knows what's in your DIC: https://github.com/phpstan/phpstan-symfony#configuration
Seems related to https://github.com/phpstan/phpstan-symfony#constant-hassers
@VincentLanglet I don't think so, they don't have the configuration to read DIC contents yet.
Disabling constant_hassers does not fix the problem. To be noted that if I split:
if ($this->has('sonata.media.manager.category') && $this->has('sonata.media.manager.context')) {
// do stuff that requires both managers.
}
into
if ($this->has('sonata.media.manager.category')) {
// do some stuff that requires manager.category
}
if ($this->has('sonata.media.manager.context')) {
// do another things that requires manager.context
}
it works (but well my logic won't be correct because I need to check in the same conditional for both services).
Thanks @ondrejmirtes ! :)
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
We are trying to increase Sonata phpstan levels and we found a strange behavior when trying to upgrade to level 5:
https://github.com/sonata-project/SonataMediaBundle/pull/2002#discussion_r661189046
The thing is, when I have the controller with 2 checks on has for a different services on the same if, it fails:
The code is something like this:
If have tried this other approach:
The error is the same, I have tried to also invert the condition, but it fails too. In fact if I invert the condition it starts failing on other parts of the code:
Then it fails on the same initial line and on the next has check for the same service.
I tried digging into the code of this plugin but I don't understand enough of phpstan internals to find the problem, but I can provide stack traces or help debuging further if needed.