HOWTO properly lint defensive programming with covering switch #14967
Answered
by
mspirkov
homersimpsons
asked this question in
Support
|
Playground link: https://phpstan.org/r/923770c1-8beb-48a8-8929-c98c43d76697 I use defensive programming, by adding a enum A: string {
case A = 'A';
}
$a = A::A;
switch ($a) {
case A::A: break;
default:
throw new \Exception('Unhanded case `' . $a->name . '`');
}but PHPStan reports: because it sees the type as The issue is that if a case is not handled PHPStan reports nothing (by default?). I would like to be able to either:
Note that I'm not reporting this as an issue as I do not think that there is any concrete issue here. |
Answered by
mspirkov
Jul 18, 2026
Replies: 2 comments · 2 replies
|
It seems to me that this can be solved in this way: https://phpstan.org/r/3b52ffc8-8a13-4997-b43e-02267e0e01fc |
1 reply
Answer selected by
homersimpsons
|
if you want to enforce errors on missing cases, I would recommend using |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It seems to me that this can be solved in this way: https://phpstan.org/r/3b52ffc8-8a13-4997-b43e-02267e0e01fc