Skip to content

New rule: switch statements must have a default value #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 6, 2018

Conversation

moufmouf
Copy link
Member

@moufmouf moufmouf commented Jul 6, 2018

We should always check for unexpected values.

Therefore, a switch statement should always have a default case. If the code is supposed to go through on of the cases, the default statement must throw an exception.

See http://bestpractices.thecodingmachine.com/php/defensive_programming.html#always-check-for-unexpected-values

@moufmouf moufmouf merged commit 4171d44 into thecodingmachine:master Jul 6, 2018
@moufmouf moufmouf deleted the default_switch branch July 6, 2018 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant