own3d/php-cs-fixer-config

个人PHP-CS-Fixer配置

3.0.1 2023-02-10 00:00 UTC

This package is auto-updated.

Last update: 2024-09-10 03:21:32 UTC


README

Latest Stable Version Total Downloads License GitHub Build Status

个人PHP-CS-Fixer包装器及预设管理。

安装

composer require romanzipp/php-cs-fixer-config --dev

注意:如果您需要在您的vendor/bin文件夹中本地安装具有可执行文件的PHP-CS-Fixer包,则还需要安装PHP-CS-Fixer包本身

使用方法

此包已创建,用于简化多个项目的配置管理,并保持PHP CS Fixer规则更新。

.php-cs-fixer.dist.php

return romanzipp\Fixer\Config::make()
    ->in(__DIR__)
    ->preset(
        new romanzipp\Fixer\Presets\PrettyPHP()
    )
    ->out();

可用预设

您可以通过扩展AbstractPreset类轻松创建自己的预设。

覆盖预设

如果您只需要针对特定项目进行一些调整(不值得创建自己的预设),则可以使用各种方法。

$config = romanzipp\Fixer\Config::make();

$config->allowRisky(true);                  // Allow risky rules.
$config->withRules(['...']);                // Set additional rules
$config->exclude(['...']);                  // Add single or many files to the list of excluded files.
$config->excludeDirectories(['...']);       // Add single or many directories to the list of excluded directories.

访问配置和查找实例

return romanzipp\Fixer\Config::make()
    // ...
    ->finderCallback(static function (PhpCsFixer\Finder $finder): void {
        // ...
    })
    ->configCallback(static function (PhpCsFixer\Config $config): void {
        // ...
    })
    // ...
    ->out();

PHPStorm配置

先决条件

您需要在系统上全局安装PHP CS Fixer,因为PHPStorm不允许您按项目或相对项目路径设置php-cs-fixer可执行文件。

composer global require friendsofphp/php-cs-fixer

1. 启用检查

2. 选择规则集文件 .php-cs-fixer.dist.php [...]

遗憾的是,由于PHPStorm中的错误阻止用户使用相对路径,因此您必须为每个项目重复此过程,该错误防止用户使用相对路径来配置或执行.php-cs-fixer.dist.php配置或可执行文件。

解决此问题的另一个理论方法是创建一个统一的规则集文件在您的用户.composer文件夹。这种方法的缺点是只有一个规则集。

3. 通过单击“PHP CS Fixer”链接导航到质量工具

4. 选择PHP-CS-Fixer可执行文件