rectorphp /rector

Instant Upgrades and Automated Refactoring of any PHP 5.3+ code

★ 10,500⑂ 743
PHPCreated 2017-07-15getrector.com
10,500
stars
+5+6+63
743
forks
–
watchers
–
prs
–
issues
–
releases
–
discussions

README

Rector - Instant Upgrades and Automated Refactoring





Rector instantly upgrades and refactors the PHP code of your application.  It can help you in 2 major areas:

 1. Instant Upgrades

Rector now supports upgrades from PHP 5.3 to 8.5 and major open-source projects like Symfony, PHPUnit, and Doctrine. Do you want to be constantly on the latest PHP and Framework without effort?

Use Rector to handle instant upgrades for you.

 2. Automated Refactoring

Do you have code quality you need, but struggle to keep it with new developers in your team? Do you want to see smart code-reviews even when every senior developers sleeps?

Add Rector to your CI and let it continuously refactor your code and keep the code quality high.

Read our blogpost to see how to set up automated refactoring.

 Install

bash
composer require rector/rector --dev


 Running Rector

There are 2 main ways to use Rector:

- a single rule, to have the change under control
- or group of rules called sets

To use them, create a rector.php in your root directory:

bash
vendor/bin/rector


And modify it:

php
use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return RectorConfig::configure()
    // register single rule
    -withRules([
        TypedPropertyFromStrictConstructorRector::class
    ])
    // here we can define, what prepared sets of rules will be applied
    -withPreparedSets(
        deadCode: true,
        codeQuality: true
    );


Then dry run Rector:

bash
vendor/bin/rector src --dry-run


Rector will show you diff of files that it would change. To make the changes, drop --dry-run:

bash
vendor/bin/rector src


 Documentation

 Find full documentation here.
 Explore Rector Rules



 Learn Faster with a Book

Are you curious, how Rector works internally, how to create your own rules and test them and why Rector was born?
Read Rector - The Power of Automated Refactoring that will take you step by step through the Rector setup and how to create your own rules.



 Empowered by Community :heart:

The Rector community is powerful thanks to active maintainers who take care of Rector sets for particular projects.

Among there projects belong:

 palantirnet/drupal-rector
 craftcms/rector
 FriendsOfShopware/shopware-rector
 sabbelasichon/typo3-rector
 sulu/sulu-rector
 efabrica-team/rector-nette
 Sylius/SyliusRector
 CoditoNet/rector-money
 laminas/laminas-servicemanager-migration
 cakephp/upgrade
 driftingly/rector-laravel
 contao/contao-rector
 php-static-analysis/rector-rule
 ibexa/rector
 guanguans/rector-rules
 wernerkrauss/silverstripe-rector
 mspirkov/yii2-rector



 Hire us to get Job Done :muscle:

Rector is a tool that we develop and share for free, so anyone can automate their refactoring. But not everyone has dozens of hours to understand complexity of abstract-syntax-tree in their own time. That's why we provide commercial support - to save your time.

Would you like to apply Rector on your code 

Snapshot: 2026-11-10T09:35:25Z · Data license Apache-2.0 · JSON