You can use particular single rules, or whole list of rules, called "set lists":
<?php
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPreparedSets(deadCode: true, codeQuality: true);
That way you can include group of rules that focus on certain topic, e.g. in this case on dead detection. It makes config small and clear.
How can you upgrade to PHP 7.3?
<?php
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\SetList;
return RectorConfig::configure()
->withSets([SetList::PHP_73]);
If you're on PHP 8.x, you can use
withPhpSets()
instead, so for thephp83
set, you can define:- ->withSets([SetList::PHP_83]); + ->withPhpSets(php83: true);
That way you can use all the sets that are needed to upgrade your code to the desired PHP version in single line.
Do you want to migrate your annotations to native PHP 8.0 attributes?
use Doctrine\ORM\Mapping as ORM;
-/**
- * @ORM\Entity
- */
+#[ORM\Entity]
class SomeEntity
{
}
You can pick the groups you need with withAttributesSets()
method:
<?php
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withAttributesSets(symfony: true, doctrine: true);
How can I use Rector with community sets or my custom one?
<?php
use Rector\Config\RectorConfig;
use Rector\Doctrine\Set\DoctrineSetList;
return RectorConfig::configure()
->withSets([
DoctrineSetList::DOCTRINE_CODE_QUALITY,
__DIR__.'/config/rector-custom-set.php'
]);