Open
Description
Bug report
Hi @ondrejmirtes,
When a check is done directly in a if
, phpstan take it in account.
When a check is done by creating a boolean variable, which can be useful if the same check is needed to be done multiple times and/or if the check is complicated and we like to give a name for it, and using the boolean variable in the if
, phpstan does not take it in account.
I created a simple reproducer, but my usecase is using more complex checks.
Code snippet that reproduces the problem
https://phpstan.org/r/7ce7e2a4-cd78-4658-a085-ec1ef75ccbc5
Expected output
I expect the same behavior than
https://phpstan.org/r/9c3d2da1-0db5-4b06-90e0-645bdb9594f3;
Psalm does:
https://psalm.dev/r/86cb84843f
I end up with the following situation:
- If I don't add the check, phpstan is not happy about the null value.
- If I add the check, psalm complains about a RedundantCondition.
Did PHPStan help you today? Did it make you happy in any way?
Yep, I was just fixing 70 issues of level 8.