dbt / php-cs-fixer-config
De Boer Tool PHP-CS-Fixer 配置
3.0.1
2022-01-21 17:23 UTC
Requires
This package is auto-updated.
Last update: 2024-09-21 23:38:01 UTC
README
安装
composer require --dev dbt/php-cs-fixer-config
如果你还没有一个 .php_cs.dist.php
配置文件,在你的项目根目录创建一个
touch .php_cs.dist.php
然后填写它
<?php use Dbt\PhpCsFixerConfig\Loader; use PhpCsFixer\Finder; $finder = Finder::create()->in([ __DIR__ . '/src', // Add your own directories here. ]); // If you want to add your own rules. If you specify a rule that already exists // in the base ruleset, your local rule will take precedence and override the // base rule. $localRules = require(__DIR __ . '/rules.php'); $loader = Loader::new($finder, $localRules); // If you want to turn off risky tests. $loader->disallowRisky(); return $loader->getConfig();
Composer 脚本
你可以选择性地在你的 composer.json
中添加 Composer 脚本,这样你就不必每次都从供应商目录运行 PHP-CS-Fixer。例如
{ "scripts": { "cs": "php-cs-fixer fix", "cs-dry": "php-cs-fixer fix --dry-run" } }
PHPStorm
https://www.jetbrains.com/help/phpstorm/using-php-cs-fixer.html
GrumPHP
如果你希望使用 GrumPHP 来确保代码检查在 pre-commit 时运行,你可以这样做
安装 GrumPHP
composer require --dev phpro/grumphp
添加一个配置文件
touch grumphp.yml
填写它,例如
parameters: ascii: ~ tasks: phpcsfixer2: config: '.php_cs.dist.php'
许可证
MIT. 如你所愿。