serendipity_hq/rector-config

由 Serendipity HQ 使用 Rector 的自定义配置。

1.1.12 2024-09-20 09:31 UTC

README

Serendipity HQ Rector 配置

在 Serendipity HQ 的项目中使用的预定义配置。

当前状态

Phan PHPStan PSalm PHPUnit Composer PHP CS Fixer Rector

你喜欢这个库吗?
留下 ★

或者运行
composer global require symfony/thanks && composer thanks
以向你在当前项目中使用的所有库表示感谢,包括这个!

通过 Composer 安装 monolog-html-line-formatter

$ composer require serendipity_hq/rector-config

此库遵循 http://semver.org/ 版本规范。

如何使用 Serendipity HQ Rector Config

<?php

declare(strict_types = 1);

use SerendipityHQ\Integration\Rector\SerendipityHQ;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;

return static function (ContainerConfigurator $containerConfigurator) : void {
    $parameters = $containerConfigurator->parameters();

    $parameters->set(Option::PHP_VERSION_FEATURES, PhpVersion::PHP_81);
    $parameters->set(Option::PATHS, [__DIR__ . '/src', __DIR__ . '/tests']);
    $parameters->set(Option::BOOTSTRAP_FILES, [__DIR__ . '/vendor-bin/phpunit/vendor/autoload.php']);

    // Import directly the configuration from Serendipity HQ Rector Config
    $containerConfigurator->import(SerendipityHQ::SHQ_SYMFONY_APP);

    // Import the excluded rectors
    $toSkip = SerendipityHQ::buildToSkip(SerendipityHQ::SHQ_SYMFONY_APP_SKIP);
    
    // Set the rectors to exclude
    $parameters->set(Option::SKIP, $toSkip);
};

SerendipityHQ::buildToSkip() 方法是可变参数的:它可以接受你需要的任意数量的数组。

使用它来排除你不想在项目中应用的 rectors。

如果你想排除预定义配置中排除以外的其他 rectors,只需在你的 rector.php 配置文件中创建一个数组,并将其传递给 SerendipityHQ::buildToSkip()

<?php

declare(strict_types = 1);

use SerendipityHQ\Integration\Rector\SerendipityHQ;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Rector\Core\Configuration\Option;
use Rector\Core\ValueObject\PhpVersion;

return static function (ContainerConfigurator $containerConfigurator) : void {
    ...
    
    $othersToSkip = [
        \Rector\To\Exclude\Rector::class
    ];

    // Import the excluded rectors
    $toSkip = SerendipityHQ::buildToSkip(SerendipityHQ::SHQ_SYMFONY_APP_SKIP, $othersToSkip);
    
    // Set the rectors to exclude
    $parameters->set(Option::SKIP, $toSkip);
};

你喜欢这个库吗?
留下 ★

或者运行
composer global require symfony/thanks && composer thanks
以向你在当前项目中使用的所有库表示感谢,包括这个!