rectorphp /rector
Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
★ 10,509⑂ 743👁 88⑃ 4,399● 5,227▤ 205
+1
Daily
+14
Weekly
+64
Monthly
10,509
stars
743
forks
88
watchers
4,399
prs
5,227
issues
205
releases
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 Top issues
#9958System error: Class ... should be known at this point2 comments · 2026-11-03#9970Removing a skip after a `--clear-cache` run does not invalidate the cache1 comments · 2026-11-15#9966CreateStubOverCreateMockArgRector turns a mock into a stub when the argument is stored and configured with expects() later1 comments · 2026-11-14#9965AddDoesNotPerformAssertionToNonAssertingTestRector: misses assertions outside the test method body (parent::, expectUserDeprecationMessage(), lifecycle methods)1 comments · 2026-11-14#9948"System error: "Node "PhpParser\Node\Expr\ClassConstFetch" with is missing scope required for scope refresh"1 comments · 2026-10-30#9969EventSubscriberToAttributeRector breaks subscribers when nothing registers #[AsEventListener]0 comments · 2026-11-15#9956MyCLabsMethodCallToEnumConstRector should only refactor according to RuleDefinition0 comments · 2026-11-03
Discussions
#9924Getting class or namespace error when creating custom rector using the `nesbot/carbon` library2 comments · 2026-10-09#9923Composer complaints that `*.php.inc` fixture files do not comply with PSR-41 comments · 2026-10-09#99022.6.7 was considered a patch release?1 comments · 2026-09-16#9874Everything okay with the latest 2.6.5 release? Notes have weird issue links1 comments · 2026-08-31#9751Rector wrapper plugin for cPanel1 comments · 2026-05-06#9747Is there a Rector for Inline Multiline Array passed as param?1 comments · 2026-04-30#9715NullCoalescingOperatorRector rule for if (!isset($var)) $var = '...'?0 comments · 2026-03-28#9678Trying to debug the false-positive3 comments · 2026-02-25
Latest release
Released Rector 2.8.5 2.8.5 2026-11-14Bugfixes and safer reprints :bug: This release is mostly about bugfixes - an infinite loop fix in docblock return types, kept ternary parentheses on null coalescing, more precise changed_files in JSON output, and several new skips for dead code and PHP 8.4 rules. On the extension side, PHPUnit AddDoesNotPerformAssertionToNonAssertingTestRector is now faster and more precise. Bugfixes :bug: - [TypeDeclarationDocblocks] Skip invalid @return tag to fix infinite loop in DocblockReturnArrayFromDirectArrayInstanceRector (8918) - [ChangesReporting] List only changed files in JSON chang