
Rector
Automatically upgrades and refactors PHP code, from PHP 5.3 code up to newer PHP versions.
- Stars
- 10.5k
- Forks
- 742
- Licence
- MIT
- Language
- PHP
- Last update
- 5 days ago
- Type
- Dev tool
What it is
Rector is a command-line tool that scans PHP code and rewrites it using a set of rules. It can move code toward newer PHP versions and framework versions, and clean up code quality issues. Teams often run it in CI so code quality is maintained automatically.
- Preview upgrade changes on a folder with a dry run before applying them
- Apply prepared rule sets for dead code and code quality to a project
- Run Rector in CI to keep refactoring consistent across a team
- Apply framework-specific rule sets for Symfony, PHPUnit, or Doctrine
Great for
- PHP teams planning to move an older codebase to a newer PHP version
- Projects using Symfony, PHPUnit, or Doctrine that want framework-specific upgrade rules
- Teams that want automated code quality checks in continuous integration
- Developers who prefer reviewing a diff before applying changes
Not ideal for
- Non-PHP projects, since it only works on PHP code
- Teams that want fully hands-off changes without reviewing diffs, because the README recommends checking results and the tool can produce poorly formatted output
- Projects without a coding standard tool, because the README says Rector's output usually needs formatting cleanup afterward
How to get it
- 1
Install with a package manager
You'll need: PHP · Composer
Install as a dev dependency
composer require rector/rector --devPreview changes on a folder without modifying files
vendor/bin/rector src --dry-runApply changes to a folder
vendor/bin/rector src - 2
Run it
- Install Rector with Composer as a dev dependency
- Create a rector.php file in the project root and configure rules or sets
- Run vendor/bin/rector src --dry-run to preview changes
- Review the diff, then run vendor/bin/rector src to apply them
- 3
Get the most out of it
- Use single rules for changes you want to control closely, or prepared sets for broader cleanup
- Add --debug to print nested exceptions when troubleshooting
- Use --xdebug with Xdebug installed when stepping through a problem
- Pair Rector with a coding standard tool such as ECS to tidy the output, as the README suggests
Downloads
Strengths
- Covers PHP upgrades from 5.3 to 8.5 according to the README
- Dry-run mode shows diffs before any file is changed
- Rules can be used individually or grouped into sets
Trade-offs
- Output can be poorly formatted, so a coding standard tool is needed afterward
- Parallel mode may have unresolved issues on Windows, per the README
- Files mixing PHP and HTML may need manual checking after changes
How it compares
| Project | Stars | Type | Level | Updated | Best for |
|---|---|---|---|---|---|
| rector (this) | 10.5k | Dev tool | intermediate | 5 days ago | PHP teams planning to move an older codebase to a newer PHP version |
| PHP-CS-Fixer | 13.6k | Dev tool | beginner | 5 days ago | PHP teams that want consistent code style without manual review comments |
| phpstan | 14.1k | Dev tool | intermediate | 4 days ago | PHP developers who want to catch bugs earlier than tests alone allow |
| composer | 29.6k | Dev tool | beginner | 4 days ago | PHP developers starting a new project who want standard third-party libraries |
| prettier | 52.4k | Dev tool | beginner | 4 days ago | Teams that want one shared code style without writing their own rules |
| babel | 44.1k | Dev tool | intermediate | 4 days ago | Web developers who want to use recent JavaScript syntax while still supporting older browsers |
Stats synced from GitHub. The assessment above was drafted with AI from the project's README on 2026-10-29 and may miss recent changes — check the README before relying on a command. MIT licence: free to use, modify and distribute, including commercially, as long as you keep the copyright notice.