Repository navigation
Return node when node mutated in place, so change is recorded - #1087
Merged
Merged
Conversation
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.
Why
Following rectorphp/rector-src#8791, the engine skips the format-preserving print when a pass records no change (
refactor()returnsnull). Rules that mutate the AST in place but thenreturn nullon some branch now have their change silently dropped.FormTypeInstanceToClassConstRectorhit this: for the collection case ($formBuilder->add('tags', 'collection', ['entry_type' => new TagType()])),refactorCollectionOptions()rewrites$arrayItem->value(new TagType()->TagType::class) in place, but the method then returns viaprocessNewInstance($node, 1, 2), which returnsnullbecause position 1 is the string'collection', not anew. The wholerefactor()returnednulland the applied mutation was dropped.Fix
refactorCollectionOptions()now returns whether it changed anything. WhenprocessNewInstance()yields no new call but the collection options were mutated,refactor()returns the already-mutated$nodeso the change is reported through the return value per therefactor()contract. Output is unchanged - only the return value differs.Tested