You can simply install rector for TYPO3 via composer:
composer require --dev ssch/typo3-rector
Then you can have a configuration file for TYPO3 created automatically:
cp ./vendor/ssch/typo3-rector/templates/rector.php.dist rector.php
This file (rector.php) is now in your project root directory. Here you can still set which changes in the code of your extension should be checked for. The set lists and the individual services that can be loaded are particularly important. The following is a greatly simplified example of a configuration of a TYPO3 extension that was created for TYPO3 8, but is now required in TYPO3 10:
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;
use Ssch\TYPO3Rector\Configuration\Typo3Option;
use Ssch\TYPO3Rector\FileProcessor\Composer\Rector\ExtensionComposerRector;
use Ssch\TYPO3Rector\Rector\General\ConvertImplicitVariablesToExplicitGlobalsRector;
use Ssch\TYPO3Rector\Rector\General\ExtEmConfRector;
use Ssch\TYPO3Rector\Set\Typo3LevelSetList;
return static function (RectorConfig $rectorConfig): void {
$rectorConfig->sets([
Typo3LevelSetList::UP_TO_TYPO3_11
]);
$rectorConfig->phpstanConfig(Typo3Option::PHPSTAN_FOR_RECTOR_PATH);
$rectorConfig->importNames();
$rectorConfig->disableParallel();
$rectorConfig->disableImportShortClasses();
$rectorConfig->phpVersion(PhpVersion::PHP_74);
$rectorConfig->skip([
__DIR__ . '/**/Configuration/ExtensionBuilder/*',
__DIR__ . '/**/Resources/**/node_modules/*',
__DIR__ . '/**/Resources/**/NodeModules/*',
__DIR__ . '/**/Resources/**/BowerComponents/*',
__DIR__ . '/**/Resources/**/bower_components/*',
__DIR__ . '/**/Resources/**/build/*',
__DIR__ . '/vendor/*',
__DIR__ . '/Build/*',
__DIR__ . '/public/*',
__DIR__ . '/.github/*',
__DIR__ . '/.Build/*',
]);
$rectorConfig->rule(ConvertImplicitVariablesToExplicitGlobalsRector::class);
$rectorConfig->ruleWithConfiguration(ExtEmConfRector::class, [
ExtEmConfRector::ADDITIONAL_VALUES_TO_BE_REMOVED => []
]);
$rectorConfig->ruleWithConfiguration(ExtensionComposerRector::class, [
ExtensionComposerRector::TYPO3_VERSION_CONSTRAINT => ''
]);
};
And you can have your files updated automatically:
./vendor/bin/rector process private/typo3conf/ext/extensionkey --dry-run
./vendor/bin/rector process private/typo3conf/ext/extensionkey