refactor
Runs Rector for code refactoring.
Description
The refactor
command (alias: rector
) runs Rector to automatically
refactor PHP code. Without --fix
, it runs in dry-run mode.
Usage
composer refactor
composer refactor --fix
composer dev-tools:fix refactor
composer dev-tools refactor -- [options]
vendor/bin/dev-tools refactor [options]
Options
--fix, -f- Automatically fix code refactoring issues. Without this option, runs in dry-run mode.
--config, -c(optional)- Path to the Rector configuration file. Default:
rector.php. --progress- Enable progress output from Rector.
--json- Emit a structured machine-readable payload instead of the normal terminal output.
--pretty-json- Emit the same structured payload with indentation for terminal inspection.
Examples
Run Rector in dry-run mode:
composer refactor
Apply fixes automatically:
composer refactor --fix
Exit Codes
| Code | Meaning |
|---|---|
| 0 | Success. No refactoring needed or fixes applied. |
| 1 | Failure. Refactoring issues found. |
Behavior
- Local
rector.phpis preferred when present. - Packaged default includes Fast Forward custom Rector rules plus shared Rector sets.
- Progress output is disabled by default; use
--progressto re-enable it in text mode. --jsonand--pretty-jsonforward JSON mode to Rector and suppress its progress bar.- Uses
--dry-runmode unless--fixis specified.