xmarcos / php-cs-fixer-config
PHP 编码规范修复配置
v0.1.0
2017-10-09 04:10 UTC
Requires
- php: ^5.6 || ^7.0
- friendsofphp/php-cs-fixer: ^2.7
Requires (Dev)
- phpunit/phpunit: ^5.7.19
This package is not auto-updated.
Last update: 2024-09-29 04:42:55 UTC
README
一个使用我所有项目中使用的规则的 PHP 编码规范修复器 配置,用于验证和强制执行编码规范。
需求
PHP 需要至少是 PHP 5.6.0 版本。
安装
composer require --dev xmarcos/php-cs-fixer-config
使用方法
在项目的根目录下创建一个配置文件 .php_cs.dist
<?php $config = new xmarcos\PhpCsFixer\Config\Php56(); $config ->setUsingCache(true) ->getFinder() ->in(__DIR__); return $config;
⚠️ 如果
setUsingCache设置为true,请将.php_cs.cache添加到.gitignore。
默认的 Finder 配置是
$finder ->files() ->name('*.php') ->name('*.phpt') ->ignoreDotFiles(true) ->ignoreVCS(true) ->exclude('vendor');
为了强制执行 header_comment,向配置的构造函数传递一个 string
$header = <<<'EOF' (c) 2017 Marcos Sader. For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; $config = new xmarcos\PhpCsFixer\Config\Php56($header); ...
修复问题
使用 Composer 脚本
您可以使用 Composer 脚本 来运行修复器
"scripts": { "cs": "php-cs-fixer fix --config=.php_cs.dist -v --diff --dry-run", "cs-fix": "php-cs-fixer fix --config=.php_cs.dist -v --diff" }
然后运行
# to run the rules but not change/fix any files. composer cs # to change/fix files. composer cs-fix
鸣谢
受 refinery29/php-cs-fixer-config 启发。
许可证
MIT 许可证