This project contains Rector rules for Silverstripe CMS.
See the available Silverstripe rules.
Install via composer.
composer require --dev cambis/silverstripe-rectorAdd PSR-4 autoload setup in your composer.json. This will help Rector to discover your classes and give it a performance boost.
{
"autoload": {
"classmap": [
"app/src/Page.php",
"app/src/PageController.php"
],
"psr-4": {
"MyProjectNamespace\\": "app/src"
}
},
"autoload-dev": {
"psr-4": {
"MyProjectNamespace\\Tests\\": "app/tests"
}
}
}Verify everything is compliant.
composer dumpautoload -oIf you do not have an existing rector.php file, run the following command and Rector will create one for you.
vendor/bin/rectorThen use the SilverstripeLevelSetList and SilverstripeSetList sets and pick one of the constants.
<?php
declare(strict_types=1);
use Cambis\SilverstripeRector\Set\ValueObject\SilverstripeLevelSetList;
use Cambis\SilverstripeRector\Set\ValueObject\SilverstripeSetList;
use Rector\Config\RectorConfig;
return RectorConfig::configure()
->withPaths([
__DIR__ . '/app/_config.php',
__DIR__ . '/app/src',
__DIR__ . '/app/tests',
])
->withSets([
SilverstripeLevelSetList::UP_TO_SILVERSTRIPE_52,
SilverstripeSetList::CODE_QUALITY,
]);Analyse your code with Rector and review the suggested changes.
vendor/bin/rector process --dry-runApply the suggested changes after they have been reviewed.
vendor/bin/rector processFor more information on usage, please refer to the official docs.