Das Tool rector ist eine Konsolenanwendung für automatisiertes Refactoring von PHP Anwendungen.
Damit lassen sich schnell einfache Altlasten entfernen aus Legacy Projekten.
Mit dem folgenden Rector Script (./rector.php) können die gängigsten Refactorings durchgeführt werden:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Php81\Rector\Property\ReadOnlyPropertyRector;
use Rector\Set\ValueObject\SetList;
use Rector\Strict\Rector\Empty_\DisallowedEmptyRuleFixerRector;
// run with: vendor/bin/rector process --debug --dry-run
return static function (RectorConfig $rectorConfig): void {
$setLists = [
/*SetList::PHP_52,
SetList::PHP_53,
SetList::PHP_54,
SetList::PHP_55,
SetList::PHP_56,
SetList::PHP_70,
SetList::PHP_71,
SetList::PHP_72,
SetList::PHP_73,
SetList::PHP_74,
SetList::PHP_80,
SetList::PHP_81,*/
//SetList::CODE_QUALITY,
//SetList::CODING_STYLE,
//SetList::DEAD_CODE,
SetList::RECTOR_PRESET,
/*SetList::INSTANCEOF,
SetList::EARLY_RETURN,
SetList::NAMING,
SetList::PRIVATIZATION,
SetList::STRICT_BOOLEANS,
SetList::STRICT_BOOLEANS,*/
];
foreach ($setLists as $setList) {
$rectorConfig->import(
$setList
);
}
$rectorConfig->paths([
__DIR__.'/src',
__DIR__.'/tests',
]);
$rectorConfig->skip([
// do not make all constructor args readonly for mocking and unit tests
ReadOnlyPropertyRector::class,
// using empty() is fine
DisallowedEmptyRuleFixerRector::class,
]);
};
ausführbar im Dry mode ohne Änderungen am Code mit:
vendor/bin/rector process --debug --dry-run
