Conversation
…mi-colon
The PHP 8.5 deprecations RFC contains a proposal to deprecate the use of semicolons as scope openers for `switch` `case` and `default` statements.
The `PSR2.ControlStructures.SwitchDeclaration` sniff already detects and flags this issue under the `WrongOpenercase` and `WrongOpenerdefault` error codes, but as the same error code is also used for `case`/`default` statements using the `: { ... }` syntax, the error code was non-fixable.
With an eye on the PHP 8.5 deprecation, it seems prudent to ensure that a semi-colon `case`/`default` scope opener can be auto-fixed to a `colon`.
Making the `: { ... }` syntax auto-fixable may be more complex, so is left as future scope.
Includes tests.
Note: if this were a new sniff, I would probably have introduced new error code(s), so the fixable and the non-fixable errors would have separate error codes. However, as this is a pre-existing sniff, doing so would be a breaking change and not one I deem strictly necessary.
Ref:
* https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_semicolon_after_case_in_switch_statement
fredden
approved these changes
Jul 9, 2025
1 task
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The PHP 8.5 deprecations RFC contains a proposal to deprecate the use of semicolons as scope openers for
switchcaseanddefaultstatements.The
PSR2.ControlStructures.SwitchDeclarationsniff already detects and flags this issue under theWrongOpenercaseandWrongOpenerdefaulterror codes, but as the same error code is also used forcase/defaultstatements using the: { ... }syntax, the error code was non-fixable.With an eye on the PHP 8.5 deprecation, it seems prudent to ensure that a semi-colon
case/defaultscope opener can be auto-fixed to a colon.Making the
: { ... }syntax auto-fixable may be more complex, so is left as future scope.Includes tests.
Note: if this were a new sniff, I would probably have introduced new error code(s), so the fixable and the non-fixable errors would have separate error codes. However, as this is a pre-existing sniff, doing so would be a breaking change and not one I deem strictly necessary.
Suggested changelog entry
WrongOpener*error code for thePSR2.ControlStructures.SwitchDeclarationsniff is now auto-fixable if the identified "wrong opener" is a semi-colon.Related issues/external references