Skip to content

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
Step-by-step guide: how to use RectorInstall, first run, examples, tips and FAQs

How to get it

  1. 1

    Install with a package manager

    You'll need: PHP · Composer

    Install as a dev dependency

    composer require rector/rector --dev

    Preview changes on a folder without modifying files

    vendor/bin/rector src --dry-run

    Apply changes to a folder

    vendor/bin/rector src
  2. 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. 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

ProjectStarsTypeLevelUpdatedBest for
rector (this)10.5kDev toolintermediate5 days agoPHP teams planning to move an older codebase to a newer PHP version
PHP-CS-Fixer13.6kDev toolbeginner5 days agoPHP teams that want consistent code style without manual review comments
phpstan14.1kDev toolintermediate4 days agoPHP developers who want to catch bugs earlier than tests alone allow
composer29.6kDev toolbeginner4 days agoPHP developers starting a new project who want standard third-party libraries
prettier52.4kDev toolbeginner4 days agoTeams that want one shared code style without writing their own rules
babel44.1kDev toolintermediate4 days agoWeb 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.