Skip to content

PSR2 WrongOpenercase with colon and bracket is unclear#1358

Merged
jrfnl merged 1 commit intoPHPCSStandards:4.xfrom
bigdevlarry:PSR2-WrongOpenercase-with-colon-and-bracket-is-unclear
Jan 14, 2026
Merged

PSR2 WrongOpenercase with colon and bracket is unclear#1358
jrfnl merged 1 commit intoPHPCSStandards:4.xfrom
bigdevlarry:PSR2-WrongOpenercase-with-colon-and-bracket-is-unclear

Conversation

@bigdevlarry
Copy link
Copy Markdown
Contributor

@bigdevlarry bigdevlarry commented Jan 9, 2026

Updated SwitchDeclarationSniff to give a clear error when a case uses a braced block after the colon.

Description

The PR introduces a change that correct updates the SwitchDeclarationSniff to give a clear error when a case uses a braced block after the colon.

Suggested changelog entry

Improved PSR2 SwitchDeclaration sniff to detect and report case/default statements using a braced block after the colon with (CaseWithBlockScope)

Related issues/external references

Fixes #1322

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
  • I have opened a sister-PR in the documentation repository to update the Wiki.

Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigdevlarry Thanks for opening this PR, but it doesn't correctly address the issue.

  1. The PR as-is presumes this is a block with a colon + curly braces, but doesn't verify it, so there could be a situation where the error message would be shown when there are no curlies, making this a worse situation than before.
  2. The error code change is effectively a breaking change as it will break any ignore annotations referencing the original code, as well as ruleset directives referencing the original code.

As things are, I cannot accept this PR.

@bigdevlarry
Copy link
Copy Markdown
Contributor Author

Hey @jrfnl , thanks for the feedback. I've added a check, and also is there a reasoning for the failing test?

Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added a check

@bigdevlarry Thanks for that, but it looks like you did not (manually) test this change as the code is not working the way you intended it to.
See the code coverage report which shows the code never gets run: https://coveralls.io/builds/77252487/source?filename=src%2FStandards%2FPSR2%2FSniffs%2FControlStructures%2FSwitchDeclarationSniff.php

Also the error code change is still a blocker.

also is there a reasoning for the failing test?

Rate limit if the broken link check is executed too frequently ;-)

Comment thread src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php Outdated
@bigdevlarry bigdevlarry force-pushed the PSR2-WrongOpenercase-with-colon-and-bracket-is-unclear branch from c04c633 to b7cba75 Compare January 10, 2026 10:20
@bigdevlarry
Copy link
Copy Markdown
Contributor Author

bigdevlarry commented Jan 10, 2026

@jrfnl Helpful feedback again; I've now improved the conditional, did some manual test and test coverage should report nicely now :)

Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigdevlarry Thanks for the update. Not trying to be difficult, but can I please ask you to take another critical look at the code ?

Aside from the inline comments, as I've already previously pointed out, the change in the error code is a breaking change. Please justify why this should have a different error code.

Lastly, unless you can - in all honesty - place a checkmark in the third checkbox in the PR template granting the project the rights to the code, I will not be able to accept the PR.

Comment thread src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php Outdated
Comment thread src/Standards/PSR2/Sniffs/ControlStructures/SwitchDeclarationSniff.php Outdated
@bigdevlarry bigdevlarry force-pushed the PSR2-WrongOpenercase-with-colon-and-bracket-is-unclear branch from 430015d to 7c06a1d Compare January 11, 2026 14:07
@jrfnl jrfnl added this to the 4.0.2 milestone Jan 14, 2026
Copy link
Copy Markdown
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@bigdevlarry Thank you for those changes. All good now. Thank you for contributing.

@jrfnl jrfnl merged commit 44c338e into PHPCSStandards:4.x Jan 14, 2026
61 of 62 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PSR2.ControlStructures.SwitchDeclaration.WrongOpenercase with colon and bracket is unclear

2 participants