Instant Upgrades and Automated Refactoring of any PHP 5.3+ code
Go to file
Tomas Votruba 9e3e9b62ed Updated Rector to commit 9e39db80cf2a763ae6006b3747feb69d82ade52d
9e39db80cf [DeadCode] Skip has parent class with __call() magic method on RemoveParentCallWithoutParentRector (#5336)
2023-12-07 04:38:08 +00:00
.github Updated Rector to commit 16ba249bcee39137ba27b687bbfc6f15761c99c5 2023-09-27 14:51:48 +00:00
bin Updated Rector to commit e48234e23981f4022e704bc500b9a9197727e87e 2023-12-01 09:49:11 +00:00
config Updated Rector to commit b1a50d4c785b9fc1498bcd843e58635350e10114 2023-12-05 14:01:18 +00:00
docs Updated Rector to commit 005ccc330c3bb37f9faf0f5e2c319036f2d055b8 2023-12-04 14:56:20 +00:00
e2e Updated Rector to commit 01c0ea9420b424bf1484c99dbb1185a0cd1c3e61 2023-09-12 23:04:24 +00:00
packages Updated Rector to commit 79c57f019e1c94c72ef79cb6cbdda864bdc2e1c1 2023-12-06 14:25:02 +00:00
rules Updated Rector to commit 043d43cd0347b4c2a73e896674a1f22ab1ce6d62 2023-12-06 13:28:15 +00:00
src Updated Rector to commit 9e39db80cf2a763ae6006b3747feb69d82ade52d 2023-12-07 04:38:08 +00:00
stubs-rector Updated Rector to commit b6f53b95e8a0ced2dd8197f9c46640ee9010a63b 2023-12-06 23:05:01 +00:00
templates Updated Rector to commit 5595f80ed176f93485f50ff6dabad79cedbb72dc 2023-09-04 14:00:44 +00:00
vendor Updated Rector to commit d22741edaf63d488b39f7754353b0ea8cc454836 2023-12-05 21:03:16 +00:00
.gitattributes Updated Rector to commit 23e4b6631f1686ab59c0ebc962e3c4d8df181e76 2023-07-13 09:14:00 +00:00 Use HTTPS instead of HTTP 2018-02-14 07:23:09 -02:00 Updated Rector to commit 29a450266e9b34d7cc2e31e96390f52abcebc76e 2023-03-26 11:59:34 +00:00
LICENSE Update LICENSE year forever 2018-01-02 20:27:07 -02:00 Updated Rector to commit 307b9d6c470480b8dea2bee8bcf6fbcc352bbf79 2023-09-15 07:10:20 +00:00
bootstrap.php Updated Rector to commit dc22a952fe92e3574a27c8e9e7de3d9aead42a4f 2022-09-01 22:05:56 +00:00
composer.json Updated Rector to commit 547af4e8fd379a605f1b7b3e8bcc0e28b819f220 2023-09-28 18:10:06 +00:00
preload.php Updated Rector to commit 4cfe654f85ed549b39512bef2e780cc5e37d59e9 2023-08-06 00:28:43 +00:00

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.2 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.


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:


And modify it:

use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictConstructorRector;

return static function (RectorConfig $rectorConfig): void {
    // register single rule

    // here we can define, what sets of rules will be applied
    // tip: use "SetList" class to autocomplete sets with your IDE

Then dry run Rector:

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

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

vendor/bin/rector process src


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 ❤️

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

Among there projects belong:

Hire us to get Job Done 💪

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 base but don't have time for the struggle with your project? Hire us to get there faster.

How to Contribute

See the contribution guide or go to development repository rector/rector-src.


You can use --debug option, that will print nested exceptions output:

vendor/bin/rector process src/Controller --dry-run --debug

Or with Xdebug:

  1. Make sure Xdebug is installed and configured
  2. Add --xdebug option when running Rector
vendor/bin/rector process src/Controller --dry-run --xdebug

To assist with simple debugging Rector provides 2 helpers to pretty-print AST-nodes:

use PhpParser\Node\Scalar\String_;
$node = new String_('hello world!');

// prints node to string, as PHP code displays it

// dump nested node object with nested properties

// 2nd argument is how deep the nesting is - this makes sure the dump is short and useful
dump_node($node, 1);

Known Drawbacks

  • Rector uses nikic/php-parser, built on technology called an abstract syntax tree (AST). An AST doesn't know about spaces and when written to a file it produces poorly formatted code in both PHP and docblock annotations.

  • Rector in parallel mode will work most of the times for most OS. On Windows, you may encounter issues unresolvable despite of following the Troubleshooting Parallel guide. In such case, check if you are using Powershell 7 (pwsh). Change your terminal to command prompt (cmd) or bash for Windows.

How to Apply Coding Standards?

Your project needs to have a coding standard tool and a set of formatting rules, so it can make Rector's output code nice and shiny again.

We're using ECS with this setup.

May cause unexpected output on File with mixed PHP+HTML content

When you apply changes to File(s) thas has mixed PHP+HTML content, you may need to manually verify the changed file after apply the changes.