[CodingStyle] Keep trait use adaptations in SeparateMultiUseImportsRector - #8510
Merged
TomasVotruba merged 1 commit intoSep 21, 2026
Conversation
…sRector
Splitting a grouped trait use only carried Alias adaptations across, so an
insteadof was dropped along with the statement it sat on:
use A, B {
A::collide insteadof B;
}
became two plain uses with nothing left to resolve the conflict, and the
class could no longer be loaded at all. An alias naming no trait was
dropped just as silently, taking the aliased method with it.
Precedence adaptations now follow the trait they name, the same way an
alias already did. The two that cannot follow a single trait leave the
statement alone instead: one that names no trait applies to all of them,
and one that names a trait used in another statement belongs to none of
the ones being split.
Member
|
LGTM, thanks |
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.
SeparateMultiUseImportsRectoronly carriesAliasadaptations onto the splitstatements, so every other adaptation is dropped together with the grouped
statement it sat on.
The one that hurts is
insteadof:becomes
Nothing is left to resolve the conflict, so the class no longer loads:
An
Aliasthat names no trait (exec as renamed;) is dropped just as silently,taking the aliased method with it.
Fix
A
Precedenceadaptation now follows the trait it names, the same way an aliasalready did — PHP accepts the adaptation on the winning trait's own statement:
Two kinds cannot follow a single trait, and for those the statement is left
alone rather than rewritten:
of the ones being split, e.g.
use A; use B, C { A::exec insteadof B; }Tests
with_trait_use_precedence— theinsteadofcase aboveskip_unqualified_trait_use_adaptation— adaptation naming no traitskip_trait_use_adaptation_of_other_statement— adaptation naming a trait from another statementThe existing alias fixtures are unchanged.