Skip to content

Squiz/SwitchDeclarationSniff: use placeholders in error messages - #1449

Open
ntdiary wants to merge 1 commit into
PHPCSStandards:4.xfrom
ntdiary:issue-1240-squiz-switch-declaration
Open

Squiz/SwitchDeclarationSniff: use placeholders in error messages#1449
ntdiary wants to merge 1 commit into
PHPCSStandards:4.xfrom
ntdiary:issue-1240-squiz-switch-declaration

Conversation

@ntdiary

@ntdiary ntdiary commented Jul 1, 2026

Copy link
Copy Markdown
Contributor

Description

Replace string concatenation with placeholders to follow the best practice.

Suggested changelog entry

Changed:

  • Squiz.ControlStructures.SwitchDeclaration: improvements to error messages
    • CaseNotLower and DefaultNotLower error messages now expose 3 data values (previously 2).
    • CaseIndent and DefaultIndent error messages now expose 2 data values (previously 0).
    • SpaceBeforeColonCase and SpaceBeforeColonDefault error messages now expose 1 data value (previously 0).
    • BreakIndent error message now exposes 1 data value (previously 0).
    • SpacingAfterCase and SpacingAfterDefault error messages now expose 1 data value (previously 0).

Related issues/external references

related to #1240

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.

Changes are already covered by Squiz/Tests/ControlStructures/SwitchDeclarationUnitTest.inc

Replace string concatenation with placeholders to follow the best practice.
- `CaseNotLower` and `DefaultNotLower` error messages now expose
  3 data values (previously 2).
- `CaseIndent` and `DefaultIndent` error messages now expose
  2 data values (previously 0).
- `SpaceBeforeColonCase` and `SpaceBeforeColonDefault` error messages now expose
  1 data value (previously 0).
- `BreakIndent` error message now exposes 1 data value (previously 0).
- `SpacingAfterCase` and `SpacingAfterDefault` error messages now expose
  1 data value (previously 0).
@ntdiary
ntdiary force-pushed the issue-1240-squiz-switch-declaration branch from 6465f72 to 2c96141 Compare July 5, 2026 03:31
@ntdiary
ntdiary marked this pull request as ready for review July 5, 2026 03:47

@jrfnl jrfnl left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@ntdiary Thank you for this PR. Verified & looking good.

Similar to what you proposed in #1447, I can see room for removing some code duplication (strtoupper($type) function calls), but that can also be done in a follow up PR.

For the record - I've checked and this sniff is not extended, so these changes do not affect any other sniffs.

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.

2 participants