Skip to content

Return node when node mutated in place, so change is recorded - #1087

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-record-change-on-inplace-mutation
Oct 24, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
tv-record-change-on-inplace-mutation

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

Why

Following rectorphp/rector-src#8791, the engine skips the format-preserving print when a pass records no change (refactor() returns null). Rules that mutate the AST in place but then return null on some branch now have their change silently dropped.

FormTypeInstanceToClassConstRector hit 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 via processNewInstance($node, 1, 2), which returns null because position 1 is the string 'collection', not a new. The whole refactor() returned null and the applied mutation was dropped.

Fix

refactorCollectionOptions() now returns whether it changed anything. When processNewInstance() yields no new call but the collection options were mutated, refactor() returns the already-mutated $node so the change is reported through the return value per the refactor() contract. Output is unchanged - only the return value differs.

Tested

@TomasVotruba
TomasVotruba merged commit 57f32e8 into main Oct 24, 2026
8 checks passed
@TomasVotruba
TomasVotruba deleted the tv-record-change-on-inplace-mutation branch October 24, 2026 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant