Skip to main content

Rector

Since 6.0

Rector is a tool for automating PHP code refactoring. Moodle includes a Rector configuration to apply a selected set of refactoring rules to the codebase.

Installation​

From the root directory of your Moodle checkout, install the Composer dependencies:

composer install

This also installs Rector and its dependencies.

Running Rector​

Run Rector from the root directory of your Moodle checkout:

composer rector

By default, Rector uses Moodle's rector.php configuration and applies changes to the codebase. Review the changes before committing them.

Passing arguments​

To pass arguments to Rector, separate them from the Composer command with --:

composer rector -- [args]

Replace [args] with Rector's command-line arguments. For example, to preview changes without modifying any files:

composer rector -- --dry-run

To limit processing to a specific directory:

composer rector -- public/mod/forum

To see the available options:

composer rector -- --help