Préalable
Il faut un fichier composer.json
à la racine du plugin, dans lequel on déclare le dépôt composer propre à SPIP :
{
"repositories": {
"spip": {
"type": "composer",
"url": "https://get.spip.net/composer"
}
}
}
Installation
composer require --dev rector/rector spip-league/rector:"dev-main"
Configuration
La configuration se fait dans le fichier rector.php
à la racine de votre plugin :
<?php
declare(strict_types=1);
use Rector\Config\RectorConfig;
use Rector\Set\ValueObject\LevelSetList;
use SpipLeague\Component\Rector\Set\SpipSetList;
return RectorConfig::configure()
->withPaths([__DIR__])
->withRootFiles()
->withSets([SpipSetList::SPIP_41, LevelSetList::UP_TO_PHP_74])
->withSkip([
__DIR__ . '/lang',
__DIR__ . '/vendor',
])
;
On peut configurer des scripts dans le fichier composer.json
:
"scripts": {
"rector": "vendor/bin/rector process --ansi",
"rector-dry-run": "vendor/bin/rector process --dry-run --ansi"
}
Usage
composer rector-dry-run
composer rector
composer rector dossier/fichier