Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat: Introduce BlankLineAfterStatement fixer#9563

Draft
localheinz wants to merge 4 commits into
PHP-CS-Fixer:masterfrom
localheinz:feature/blank-line-after-statement
Draft

feat: Introduce BlankLineAfterStatement fixer#9563
localheinz wants to merge 4 commits into
PHP-CS-Fixer:masterfrom
localheinz:feature/blank-line-after-statement

Conversation

@localheinz
Copy link
Copy Markdown
Member

This pull request

  • introduces the BlankLineAfterStatement fixer

Follows #9540 (comment).

💁‍♂️ This is based on existing work, most importantly, @erickskrauch's work on https://github.com/erickskrauch/php-cs-fixer-custom-fixers/blob/1.3.1/src/Fixer/Whitespace/LineBreakAfterStatementsFixer.php.

@localheinz localheinz self-assigned this Apr 15, 2026
Comment on lines +59 to +60
'if' => \T_IF,
'switch' => \T_SWITCH,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We could also consider folding the BlankLineAfterNamespaceFixer into this fixer:

Suggested change
'if' => \T_IF,
'switch' => \T_SWITCH,
'if' => \T_IF,
'namespace' => \T_NAMESPACE,
'switch' => \T_SWITCH,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I would only do this if you also merge the BlankLineBeforeNamespace into the BlankLineBeforeStatement too.

@coveralls
Copy link
Copy Markdown

coveralls commented Apr 15, 2026

Coverage Report for CI Build 25506351237

Coverage decreased (-0.007%) to 93.798%

Details

  • Coverage decreased (-0.007%) from the base build.
  • Patch coverage: 9 uncovered changes across 1 file (145 of 154 lines covered, 94.16%).
  • 3 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
src/Fixer/Whitespace/BlankLineAfterStatementFixer.php 154 145 94.16%

Coverage Regressions

3 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
src/Runner/Runner.php 3 72.3%

Coverage Stats

Coverage Status
Relevant Lines: 32037
Covered Lines: 30050
Line Coverage: 93.8%
Coverage Strength: 51.55 hits per line

💛 - Coveralls

Comment on lines +56 to +62
'do' => \T_DO,
'for' => \T_FOR,
'foreach' => \T_FOREACH,
'if' => \T_IF,
'switch' => \T_SWITCH,
'try' => \T_TRY,
'while' => \T_WHILE,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

One thing about these (except declare):

  • maybe we should also include match?
  • are these statements or something else ("blocks")?
  • should these be addressed by a different fixer with a more appropriate name?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

if switch is included, then imho so should match

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 15, 2026

Codecov Report

❌ Patch coverage is 94.15584% with 9 lines in your changes missing coverage. Please review.
✅ Project coverage is 94.06%. Comparing base (7f68fc3) to head (b9547bd).

Files with missing lines Patch % Lines
.../Fixer/Whitespace/BlankLineAfterStatementFixer.php 94.15% 9 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##             master    #9563      +/-   ##
============================================
- Coverage     94.07%   94.06%   -0.01%     
- Complexity    10860    10905      +45     
============================================
  Files           583      584       +1     
  Lines         34171    34325     +154     
============================================
+ Hits          32145    32287     +142     
- Misses         2026     2038      +12     

☔ View full report in Codecov by Sentry.
📢 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.

/**
* {@inheritdoc}
*
* Must run after NoUselessElseFixer.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It should also run after DeclareStrictTypesFixer and FullyQualifiedStrictTypesFixer, see PR #9540 and issue #9496


List of statements which must be followed by an empty line.

Allowed values: a subset of ``['declare', 'do', 'for', 'foreach', 'if', 'switch', 'try', 'while']``
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

the before version also has require(_once) and include(_once), does it make sense to add those too?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same for yield(_from)

['statements' => ['try']],
];

yield 'try-catch-finally - blank line inserted after the end of the whole chain' => [
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Does it also work with multiple catch blocks?
What about try {} finally {} without catch?

@localheinz localheinz force-pushed the feature/blank-line-after-statement branch from 46ac6bc to b9547bd Compare May 7, 2026 15:44
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.

3 participants