joselc/php-cs-fixer-custom-fixers

为PHP编码标准修复器设置意见规则

v1.0.1 2022-08-30 12:28 UTC

This package is auto-updated.

Last update: 2024-09-29 06:14:50 UTC


README

php-cs-fixer设置意见规则。

如果使用thecodingmachine/safe,将自动添加Safe提供的导入规则。

安装

composer require --dev josecl/php-cs-fixer-custom-fixers

使用

在你的PHP编码标准修复器配置文件(通常是.php-cs-fixer.dist.php)中,你应该使用Josecl\PhpCsFixerCustomFixers\CustomConfig代替PhpCsFixer\Config,它已经定义了规则集。

<?php

use Josecl\PhpCsFixerCustomFixers\CustomConfig;

$finder = Symfony\Component\Finder\Finder::create()
    ->in([
        __DIR__ . '/app',
        __DIR__ . '/config',
        // etc...
    ])
    ->name('*.php')
    ->notName('*.blade.php')
    ->ignoreDotFiles(true)
    ->ignoreVCS(true);

return (new CustomConfig())->setFinder($finder);

你可以通过extraRules参数自定义规则集。

return (new CustomConfig(extraRules: [
    'yoda_style' => ['equal' => true],
    // ...
]))->setFinder($finder);