gomzyakov/php-cs-fixer-config

基于PSR-12的`php-cs-fixer`代码风格配置。


README

packagist downloads_count license codecov

本包允许在不复制粘贴配置文件的情况下,在整个项目中共享相同的php-cs-fixer格式化规则。

快速入门

第3步中的第1步

通过Composer安装friendsofphp/php-cs-fixer和此包

composer require --dev friendsofphp/php-cs-fixer gomzyakov/php-cs-fixer-config

第3步中的第2步

然后在项目根目录创建文件.php-cs-fixer.dist.php,内容如下

<?php

use Gomzyakov\CS\Finder;
use Gomzyakov\CS\Config;

// Routes for analysis with `php-cs-fixer`
$routes = ['./src', './tests'];

return Config::createWithFinder(Finder::createWithRoutes($routes));

根据项目源代码的位置更改$routes的值。

第3步中的第3步

就这样!现在您可以使用以下命令查找代码风格违规

./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run

然后完全修复所有违规

./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php

配置

您必须向Finder::createWithRoutes()调用传递一组路由。例如,对于Laravel项目,这将如下所示

Finder::createWithRoutes(['./app', './config', './database', './resources', './routes', './tests'])

此外,您还可以向Config::createWithFinder()调用传递一组自定义规则

Config::createWithFinder($finder, [
    '@PHP81Migration'   => true,
    'array_indentation' => false
])

Laravel Pint

以下描述了与friendsofphp/php-cs-fixer结合使用样式的方法。您还可以使用这些样式设置Laravel Pint

支持

如果您发现任何包错误,请在此存储库中创建一个问题

许可证

这是一个开源软件,许可协议为MIT License

特别感谢