Skip to content

Fix ControlStructureSpacing sniff requiring blank line around "finally"#114

Merged
aik099 merged 1 commit into
masterfrom
fix/control-structure-spacing-finally
Jul 23, 2026
Merged

Fix ControlStructureSpacing sniff requiring blank line around "finally"#114
aik099 merged 1 commit into
masterfrom
fix/control-structure-spacing-finally

Conversation

@aik099

@aik099 aik099 commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Summary

  • Fixes ControlStructureSpacing sniff requires (and enforces) a blank line around "finally" #113CodingStandard.WhiteSpace.ControlStructureSpacing wrongly required (and auto-inserted) a blank line before finally, for both try/finally and try/catch/finally.
  • Root cause: this sniff was forked from Squiz.WhiteSpace.ControlStructureSpacing in 2014, before upstream added finally handling in 2018 (commit eefb31c68, fixing the identical NoLineAfterClose bug). The fork never picked up that later fix.
  • Mirrors the existing T_CATCH handling: registers T_FINALLY, adds an isFinally() helper, and exempts finally in both the leading-content (checkLeadingContent()) and trailing-content (checkTrailingContent()) adjacency checks.

Test plan

  • Added try/finally and try/catch/finally fixtures to ControlStructureSpacingUnitTest.1.inc — two valid (no error) and two invalid (blank line before finally, flagged and auto-fixed), regenerated .inc.fixed.
  • vendor/bin/phpunit CodingStandard/Tests/WhiteSpace/ControlStructureSpacingUnitTest.php passes.
  • Full suite (vendor/bin/phpunit) passes.

@codecov

codecov Bot commented Jul 23, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.74%. Comparing base (fe2bae3) to head (2569dd9).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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
aik099 force-pushed the fix/control-structure-spacing-finally branch from 07f8630 to 2569dd9 Compare July 23, 2026 11:14
@aik099
aik099 merged commit d70db2a into master Jul 23, 2026
18 of 19 checks passed
@aik099
aik099 deleted the fix/control-structure-spacing-finally branch July 23, 2026 11:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ControlStructureSpacing sniff requires (and enforces) a blank line around "finally"

1 participant