Skip to content

False positive: PHPStan thinks UnhandledMatchError can be thrown from boolean match expression that already handles both cases #6910

@ZebulanStanphill

Description

@ZebulanStanphill

Bug report

Starting in PHPStan 1.5.0, a false positive is reported for those using @throws: PHPStan thinks UnhandledMatchError can be thrown from a boolean match expression that already handles both the true and false cases. This false positive did not occur in PHPStan 1.4.10, though I do vaguely recall

Code snippet that reproduces the problem

https://phpstan.org/r/20c86b82-3666-4274-833b-5b3ea7c1dc33

Expected output

The match expression here should obviously never throw, and no error was reported in PHPStan 1.4.10.

Did PHPStan help you today? Did it make you happy in any way?

I've recently been setting up a bunch of code quality stuff for my project like PHPCS and PHPUnit, and for the latter, it was really nice to have the PHPStan extension to quickly catch mistakes while writing unit tests. I also recently discovered https://github.com/symplify/phpstan-rules, which has provided some nice extra rules to further tighten my codebase.

(By the way, if anyone knows of a PHPStan extension containing a rule to ban comparing certain (or all) objects with both === and ==, let me know.)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions