rector
Automated PHP code refactoring and upgrades
TLDR
SYNOPSIS
rector command [--dry-run] [--config file] [options] [paths]
DESCRIPTION
Rector performs automated refactoring of PHP codebases, applying rule-based transformations to upgrade syntax, modernize framework usage, and enforce code quality standards. It parses PHP files into an abstract syntax tree and applies configured rules to transform old constructs into their modern equivalents, handling PHP version upgrades (e.g., PHP 7.4 to 8.2) and framework migration (Symfony, Laravel, PHPUnit) automatically.The --dry-run flag previews all changes without modifying files, making it safe to review transformations before applying them. Rules are organized into sets for common upgrade paths, and custom rules can be written for project-specific refactoring patterns. The tool is typically configured through a rector.php file that specifies which rule sets and individual rules to apply.
PARAMETERS
process
Run refactoring on the specified paths.init
Create a starter rector.php configuration file.list-rules
Show all loaded and skipped rules. Accepts --config and --output-format json.setup-ci
Generate a CI workflow file (GitHub Actions or GitLab CI) for automated Rector runs.custom-rule
Generate a custom rule with boilerplate structure and PSR-4 autoload paths.--dry-run
Show changes without applying.--config FILE
Configuration file.--clear-cache
Clear cache before processing.--only RULE
Run only a single specified rule class.--output-format FORMAT
Output format (e.g., json) for piping results to other tools.-v, --verbose
Verbose output.--debug
Print nested exception traces.
CONFIGURATION
rector.php
Main configuration file defining rule sets, individual rules, paths to process, and skip patterns. Generated by rector init.
CAVEATS
Review dry-run output carefully. Complex code may need manual fixes. Git commit before running.
HISTORY
Rector was created by Tomas Votruba for automated PHP refactoring. It enables safe, large-scale codebase modernization.
SEE ALSO
phpstan(1), php-cs-fixer(1), phpcs(1), composer(1)
