Fix ControlStructureSpacing sniff requiring blank line around "finally"#114
Merged
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #114 +/- ##
=========================================
Coverage 97.73% 97.74%
- Complexity 498 502 +4
=========================================
Files 29 29
Lines 1460 1465 +5
=========================================
+ Hits 1427 1432 +5
Misses 33 33 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
The sniff was forked from Squiz.WhiteSpace.ControlStructureSpacing in 2014, before upstream added finally handling in 2018 (fixing the same NoLineAfterClose bug for itself). This fork never picked up that fix, so try/finally and try/catch/finally blocks were treated as ordinary trailing code rather than a continuation of the try/catch chain, wrongly demanding (and auto-inserting) a blank line before finally. Mirrors the existing T_CATCH handling: registers T_FINALLY, adds an isFinally() helper, and exempts finally in both the leading- and trailing-content adjacency checks. Fixes #113
aik099
force-pushed
the
fix/control-structure-spacing-finally
branch
from
July 23, 2026 11:14
07f8630 to
2569dd9
Compare
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.
Summary
CodingStandard.WhiteSpace.ControlStructureSpacingwrongly required (and auto-inserted) a blank line beforefinally, for bothtry/finallyandtry/catch/finally.Squiz.WhiteSpace.ControlStructureSpacingin 2014, before upstream addedfinallyhandling in 2018 (commiteefb31c68, fixing the identicalNoLineAfterClosebug). The fork never picked up that later fix.T_CATCHhandling: registersT_FINALLY, adds anisFinally()helper, and exemptsfinallyin both the leading-content (checkLeadingContent()) and trailing-content (checkTrailingContent()) adjacency checks.Test plan
try/finallyandtry/catch/finallyfixtures toControlStructureSpacingUnitTest.1.inc— two valid (no error) and two invalid (blank line beforefinally, flagged and auto-fixed), regenerated.inc.fixed.vendor/bin/phpunit CodingStandard/Tests/WhiteSpace/ControlStructureSpacingUnitTest.phppasses.vendor/bin/phpunit) passes.