Rector

Rector is an automated refactoring tool for PHP that applies a set of configurable transformation rules to modernize your codebase. It enables seamless upgrades to newer PHP versions or frameworks by rewriting code without manual intervention.

Using Rector can save significant time during migrations by automating repetitive refactoring tasks, reducing the risk of human error. Additionally, it promotes adherence to modern coding standards and best practices, making it an invaluable asset for maintaining a future-proof and robust codebase.

Note that when Rector makes changes to your code base, you typically need to re-run ECS so that formatting is corrected.

Foster Commerce Package

Example config

TODO setup and link to a repo that has code quality tooling

User guide

https://getrector.com/documentation

Usage

Warning: Rector changes are destructive and need to be thoroughly reviewed. Blindly committing changes made by Rector is discouraged.

In a PHP app/website

We typically use DDEV for local development of PHP apps or websites. As such, Rector should be run from within ddev.

To check for and review possible changes, run:

ddev composer run rector:dry-run

To apply changes:

ddev composer run rector:fix

In a PHP package

When working on a PHP package, such as a Craft plugin, we typically use composer directly, not from inside ddev. Rector can be run directly, instead of from within ddev.

To check for and review possible changes, run:

composer run rector:dry-run

To apply changes:

composer run rector:fix