PSR2/SwitchDeclaration: remove dead code, bow out on parse errors - #1489
Open
ntdiary wants to merge 1 commit into
Open
PSR2/SwitchDeclaration: remove dead code, bow out on parse errors#1489ntdiary wants to merge 1 commit into
ntdiary wants to merge 1 commit into
Conversation
- Bow out when a CASE/DEFAULT token is missing a scope opener or closer,
avoiding undefined array key access.
- Remove the unreachable `WrongOpener . $type` fallback error message.
The tokenizer can initially set a CASE/DEFAULT scope opener to `T_COLON`,
`T_SEMICOLON`, `T_CLOSE_TAG`. The only exception is a braced block after
the colon (`case x: { ... }`), where `processAdditional()` later
reassigns the opener to `T_OPEN_CURLY_BRACKET`.
- Cache `strtoupper($type)` in `$typeUc` instead of calling it repeatedly.
Tests: rename the existing case file to SwitchDeclarationUnitTest.1.inc and
add parse-error case files (.2.inc, .3.inc) verifying the sniff stays
silent on broken switch statements.
ntdiary
force-pushed
the
issue-1472-psr2-error-message-followup
branch
from
August 27, 2026 01:21
aee4292 to
69c4e4f
Compare
ntdiary
marked this pull request as ready for review
August 27, 2026 01:35
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
WrongOpener . $typefallback error message. The tokenizer can initially set a CASE/DEFAULT scope opener toT_COLON,T_SEMICOLON,T_CLOSE_TAG. The only exception is a braced block after the colon (case x: { ... }), whereprocessAdditional()later reassigns the opener toT_OPEN_CURLY_BRACKET.strtoupper($type)in$typeUcinstead of calling it repeatedly.Tests: rename the existing case file to SwitchDeclarationUnitTest.1.inc and add parse-error case files (.2.inc, .3.inc) verifying the sniff stays silent on broken switch statements.
Suggested changelog entry
PSR2.ControlStructures.SwitchDeclarationSniff: preventUndefined array keywarnings when the sniff encounters a CASE/DEFAULT statement without a scope opener or closer (parse error / live coding).Related issues/external references
Fixes #1472
Types of changes
PR checklist