Skip to content

chore: add Rector rules for setter refactorings#6495

Merged
gharlan merged 1 commit into
6.xfrom
chore/rector-setter-rules
May 9, 2026
Merged

chore: add Rector rules for setter refactorings#6495
gharlan merged 1 commit into
6.xfrom
chore/rector-setter-rules

Conversation

@gharlan
Copy link
Copy Markdown
Member

@gharlan gharlan commented May 9, 2026

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 $this and setter calls embedded in other expressions stay intact.
  • SetterCallToConstructorArgumentRector — merges a setter call directly following a new assignment 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 MethodCallToPropertyAssignRector for the existing ArticleSliceAction::setSave conversion (resolving the // todo setter marker in rector.php). SetterCallToConstructorArgumentRector ships unconfigured here — it will be wired up in the follow-up API-functions PR.

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>
@gharlan gharlan added this to the REDAXO 6.0 milestone May 9, 2026
@gharlan gharlan requested a review from Copilot May 9, 2026 08:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MethodCallToPropertyAssignRector in rector.php for ArticleSliceAction::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.

@gharlan gharlan merged commit 5777ab9 into 6.x May 9, 2026
20 checks passed
@gharlan gharlan deleted the chore/rector-setter-rules branch May 9, 2026 08:33
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.

2 participants