Skip to content

Improvements to switch/case exhaustiveness checking #3488

@Firehed

Description

@Firehed

Feature request

When using the const-as-enum pattern (supported in 0.12.20 via #2904), it would be really helpful to improve several warnings. Turning on strict rules does handle explicitly invalid cases (IMO that should be in the default rules, but that's a different conversation), but defaults get a bit weird:

  • Exhausting all switch cases should arguably mark the default case as unreachable
  • If all cases have been covered, the lack of a default should not result in a "method xyz should return type but return statement is missing" error
  • It would be helpful if the error for case-mismatch was on the case line rather than switch

https://phpstan.org/r/e3457146-1c41-4e70-9740-fe5d67f7f987

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions