jreklund/php-cs-fixer-compat

为已更改的旧规则提供兼容层

v1.0.2 2024-08-07 08:05 UTC

This package is auto-updated.

Last update: 2024-09-07 08:23:05 UTC


README

PHP-CS-Fixer v3.61.1(或更高版本)中使用旧版本的规则。

安装

composer require --dev jreklund/php-cs-fixer-compat

要求

为了使此包正常工作,您必须安装 friendsofphp/php-cs-fixerphp-cs-fixer/shim(推荐)。

composer require --dev friendsofphp/php-cs-fixer
composer require --dev php-cs-fixer/shim

使用方法

$config = new PhpCsFixer\Config();

return $config
    ->registerCustomFixers([
        new PhpCsFixerCompat\Fixer\Basic\BracesFixer380(),
    ])
    ->setRules([
        '@PER' => true,
        'control_structure_braces' => false,
        'control_structure_continuation_position' => false,
        'braces_position' => false,
        'no_multiple_statements_per_line' => false,
        'statement_indentation' => false,
        'PhpCsFixerCompat/braces_380' => true,
    ])
    ->setFinder(
        PhpCsFixer\Finder::create()
        ->exclude('vendor')
        ->in(__DIR__)
    );

PHP-CS-Fixer/shim

⚠️ 根据 PHP-CS-Fixer/shim 的执行方式,您可能需要手动加载 bootstrap.php,在您的 .php-cs-fixer.php 中通过 require 它。

$compatPath = implode(DIRECTORY_SEPARATOR, [
    __DIR__,
    'vendor',
    'jreklund',
    'php-cs-fixer-compat',
]);

$bootstrap = $compatPath . DIRECTORY_SEPARATOR . 'bootstrap.php';

if (file_exists($bootstrap)) {
    require $bootstrap;
}

// config starts here

规则

所有兼容规则遵循相同的命名规范:PhpCsFixerCompat/{rule}_{version}

所有修复器都可以在以下命名空间下找到:PhpCsFixerCompat\Fixer\{custom-fixer}