Skip to content

Fix AlphabeticalUseStatements sorting trait use statements#235

Merged
mmoll merged 1 commit intomayflower:masterfrom
Khartir:fix/alphabetical-use-statements-ignore-trait-use
Mar 15, 2026
Merged

Fix AlphabeticalUseStatements sorting trait use statements#235
mmoll merged 1 commit intomayflower:masterfrom
Khartir:fix/alphabetical-use-statements-ignore-trait-use

Conversation

@Khartir
Copy link
Collaborator

@Khartir Khartir commented Mar 10, 2026

Type of PR

  • Bugfix

Description

The sniff was incorrectly processing trait use statements inside class/trait/enum bodies. The parent class's private shouldIgnoreUse() filtered them out, but the child class continued executing its own sorting logic. Add a hasCondition() check to also ignore trait use.
In theory, this would sort trait use statements as well, but it does not handle traits with docblocks (generic traits are a thing).
I assume the entire handling of traits was a bug.

I thought about adding https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassestraituseorder- and maybe https://github.com/slevomat/coding-standard/blob/master/doc/classes.md#slevomatcodingstandardclassestraitusespacing- but those have also issues with docblocks on traits.

@codecov
Copy link

codecov bot commented Mar 10, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (741e2b8) to head (f498320).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##              master      #235   +/-   ##
===========================================
  Coverage     100.00%   100.00%           
  Complexity       143       143           
===========================================
  Files              8         8           
  Lines            661       652    -9     
===========================================
- Hits             661       652    -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@Khartir Khartir force-pushed the fix/alphabetical-use-statements-ignore-trait-use branch from 85c8916 to a783507 Compare March 10, 2026 12:20
The sniff was incorrectly processing trait use statements inside
class/trait/enum bodies. The parent class's private shouldIgnoreUse()
filtered them out, but the child class continued executing its own
sorting logic. Add a hasCondition() check to also ignore trait use.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Khartir Khartir force-pushed the fix/alphabetical-use-statements-ignore-trait-use branch from a783507 to f498320 Compare March 10, 2026 12:32
@sonarqubecloud
Copy link

@mmoll mmoll self-requested a review March 10, 2026 16:32
@mmoll
Copy link
Contributor

mmoll commented Mar 10, 2026

@xalopp WDYT?

@xalopp
Copy link
Collaborator

xalopp commented Mar 10, 2026

@mmoll it looks good at first sight, but I need some time for testing. Give me 48h to check ;-)

@mmoll mmoll merged commit dffc68a into mayflower:master Mar 15, 2026
16 checks passed
@mmoll
Copy link
Contributor

mmoll commented Mar 15, 2026

Merged and released in v11.0.2, thanks @Khartir!

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