cambis/silverstripe-rector

Rector rules for Silverstripe.

v0.8.3 2025-02-20 01:50 UTC

README

This project contains Rector rules for Silverstripe CMS.

See the available Silverstripe rules.

Installation 👷‍♀️

Install via composer.

composer require --dev cambis/silverstripe-rector

Recommended 💡

Add 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 -o

Configuration 🚧

If you do not have an existing rector.php file, run the following command and Rector will create one for you.

vendor/bin/rector

Then 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,
    ]);

Usage 🏃

Analyse your code with Rector and review the suggested changes.

vendor/bin/rector process --dry-run

Apply the suggested changes after they have been reviewed.

vendor/bin/rector process

For more information on usage, please refer to the official docs.