Runs Rector for code refactoring.
The refactor command (alias: rector) runs Rector to automatically
refactor PHP code. Without --fix, it runs in dry-run mode. It can also run
Type Perfect
as a follow-up PHPStan safety pass when the companion packages are installed.
composer refactor
composer refactor --fix
composer dev-tools:fix refactor
composer dev-tools refactor -- [options]
vendor/bin/dev-tools refactor [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. --type-perfect- Runs Type Perfect after Rector using a generated PHPStan config in
tmp/cache/phpstan/type-perfect.neon. --type-perfect-groups=<groups>(optional)Comma-separated Type Perfect groups to enable. Supported groups:
null_over_false,no_mixed, andnarrow_param.Default:
null_over_false,no_mixed,narrow_param.
Run Rector in dry-run mode:
composer refactorApply fixes automatically:
composer refactor --fixRun Rector and Type Perfect together:
composer dev-tools refactor -- --type-perfectLimit Type Perfect to selected groups:
composer dev-tools refactor -- --type-perfect --type-perfect-groups=null_over_false,no_mixed| Code | Meaning |
|---|---|
| 0 | Success. No refactoring needed or fixes applied. |
| 1 | Failure. Refactoring issues found. |
- Local
rector.phpis preferred when present. - Packaged default includes Fast Forward custom Rector rules plus shared Rector sets.
- Uses
--dry-runmode unless--fixis specified. --type-perfectrequiresrector/type-perfectandphpstan/extension-installerin the consumer project.- When the consumer already has
phpstan.neonorphpstan.neon.dist, the generated Type Perfect config includes it automatically before enabling the requested Type Perfect groups.