chore: add Rector rules for setter refactorings#6495
Merged
Conversation
Adds two custom Rector rules for the 5→6 upgrade set and future refactorings: - MethodCallToPropertyAssignRector: turns `$obj->setX($v);` statements into `$obj->x = $v;`. Only stand-alone statements are touched, so fluent setter return values stay intact. - SetterCallToConstructorArgumentRector: merges a setter call directly following `new` into a named constructor argument. Conditional or non-adjacent setters are left for manual cleanup. Also configures MethodCallToPropertyAssignRector for the existing ArticleSliceAction::setSave conversion (filling the `// todo setter` gap). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds two custom Rector rules to support the ongoing 5→6 upgrade refactorings, and wires one of them into the project’s rector.php config to automate a specific setter-to-property migration.
Changes:
- Add
MethodCallToPropertyAssignRector(+ value object) to convert stand-alone setter statements into property assignments. - Add
SetterCallToConstructorArgumentRector(+ value object) to merge adjacent setter calls into named constructor arguments (rule included but not yet configured). - Configure
MethodCallToPropertyAssignRectorinrector.phpforArticleSliceAction::setSave→$action->save = ...conversion.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rector.php | Imports the new value object and configures MethodCallToPropertyAssignRector for ArticleSliceAction::setSave. |
| .tools/rector/ValueObject/SetterCallToConstructorArgument.php | Adds configuration value object for the constructor-argument merge rule. |
| .tools/rector/ValueObject/MethodCallToPropertyAssign.php | Adds configuration value object for the setter-to-property-assign rule. |
| .tools/rector/Rule/SetterCallToConstructorArgumentRector.php | Implements configurable Rector rule to merge adjacent setter calls into named constructor args. |
| .tools/rector/Rule/MethodCallToPropertyAssignRector.php | Implements configurable Rector rule to replace setter statements with property assignments. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.
Summary
Adds two custom Rector rules that are useful for the in-progress 5→6 upgrade set and for future refactorings:
MethodCallToPropertyAssignRector— turns stand-alone setter statements$obj->setX($v);into$obj->x = $v;. Only statement-form calls are touched, so fluent setters returning$thisand setter calls embedded in other expressions stay intact.SetterCallToConstructorArgumentRector— merges a setter call directly following anewassignment into a named constructor argument (new Foo(...); $foo->setX($v);→new Foo(..., x: $v);). Conditional or non-adjacent setters are left for manual cleanup.Configures
MethodCallToPropertyAssignRectorfor the existingArticleSliceAction::setSaveconversion (resolving the// todo settermarker inrector.php).SetterCallToConstructorArgumentRectorships unconfigured here — it will be wired up in the follow-up API-functions PR.