gomzyakov/php-code-style

此包已被废弃,不再维护。作者建议使用 https://github.com/gomzyakov/php-cs-fixer-config 包。

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


README

packagist downloads_count license codecov

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

快速入门

第 1 步,共 3 步

使用 Composer 安装 friendsofphp/php-cs-fixer 及此包

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

第 2 步,共 3 步

然后在项目的根目录下创建文件 .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 许可证

特别感谢