Automatically update a PHP 7 codebase to PHP 8 syntax by running Rector with the appropriate upgrade rule set.
Add Rector to a CI pipeline to enforce code quality rules and reject PRs that introduce deprecated patterns.
Migrate a Symfony, PHPUnit, or Doctrine project to a newer major version by applying the relevant named rule sets.
Preview every change Rector will make as a diff using dry-run mode before any files are modified.
Run a formatter like ECS after Rector because AST re-serialization may alter whitespace and code style.
Rector is a command-line tool for PHP developers that automatically upgrades and rewrites PHP code. Instead of manually tracking deprecations or breaking changes when moving to a newer version of PHP or a framework like Symfony, PHPUnit, or Doctrine, you point Rector at your codebase and it applies the necessary transformations for you. It supports PHP versions from 5.3 up to 8.5. The tool works by parsing your PHP files into an abstract syntax tree, applying transformation rules, and writing the modified files back. You configure it with a rector.php file at the root of your project, where you specify which individual rules or named rule sets to run. A dry-run mode lets you preview every change as a diff before anything is actually written, so you can inspect the proposed modifications first. Beyond version upgrades, Rector can be added to a continuous integration pipeline to enforce code quality rules automatically. If your team introduces patterns you want to avoid, a Rector rule can catch and rewrite them on every commit, acting as a kind of automated code review for structural issues. There is an active community that maintains rule sets for specific PHP frameworks and platforms beyond the core ones, including Drupal, Laravel, Shopware, TYPO3, CakePHP, Silverstripe, and others. The company behind Rector also offers paid consulting for teams that want help applying it to large or complex codebases. A known limitation is that because the tool parses and re-serializes PHP through an AST library, the output may lose original whitespace and formatting. The recommendation is to run a separate code formatter like ECS after Rector to clean up the style. On Windows, there can also be issues with parallel processing mode that may require switching to a command prompt terminal.
← rectorphp on gitmyhub — every repo by this author, as a profile.
Verify against the repo before relying on details.