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.

Install

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:

vendor/bin/rector

And modify it:

use RectorConfigRectorConfig; use RectorSetValueObjectSetList; use RectorTypeDeclarationRectorPropertyTypedPropertyFromStrictConstructorRector; return static function (RectorConfig $rectorConfig): void { // register single rule $rectorConfig->rule(TypedPropertyFromStrictConstructorRector::class); // here we can define, what sets of rules will be applied // tip: use "SetList" class to autocomplete sets with your IDE $rectorConfig->sets([ SetList::CODE_QUALITY ]); };

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

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

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

Hire us to get Job Done

版权声明:

1、该文章(资料)来源于互联网公开信息,我方只是对该内容做点评,所分享的下载地址为原作者公开地址。
2、网站不提供资料下载,如需下载请到原作者页面进行下载。
3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考学习用!
4、如文档内容存在违规,或者侵犯商业秘密、侵犯著作权等,请点击“违规举报”。