lin3s / php-cs-fixer-config
用于LIN3S项目的PHP代码风格检查工具
v1.0.2
2017-11-03 08:46 UTC
Requires
- php: ^7.1
- friendsofphp/php-cs-fixer: ^2.2
Requires (Dev)
- phpspec/phpspec: ^3.2
This package is not auto-updated.
Last update: 2024-09-22 07:49:02 UTC
README
用于LIN3S项目的PHP代码风格检查工具,基于PHP CS Fixer
安装
$ composer require --dev lin3s/php-cs-fixer-config
用法
配置
在项目的根目录下创建一个配置文件.php_cs
<?php /* * This file is part of the PhpCsFixerConfig project. * * Copyright (c) 2017-present LIN3S <info@lin3s.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); use LIN3S\PhpCsFixerConfig\Lin3sConfig; $config = new Lin3sConfig('LIN3S awesome project', '2017', 'project'); $config->getFinder()->in(__DIR__ . '/src'); $cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; $config->setCacheFile($cacheDir . '/.php_cs.cache'); return $config;
如果您的项目使用PhpSpec BDD测试框架,也在项目的根目录下创建一个.phpspec_cs
文件
<?php /* * This file is part of the PhpCsFixerConfig project. * * Copyright (c) 2017-present LIN3S <info@lin3s.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ declare(strict_types=1); use LIN3S\PhpCsFixerConfig\Lin3sConfig; $config = new Lin3sConfig('LIN3S awesome project', '2017', 'project', true); $config->getFinder() ->in(__DIR__ . '/spec') ->name('*Spec.php'); $cacheDir = getenv('TRAVIS') ? getenv('HOME') . '/.php-cs-fixer' : __DIR__; $config->setCacheFile($cacheDir . '/.php_cs.cache'); return $config;
Git
将.php_cs.cache
(这是由php-cs-fixer
创建的缓存文件)添加到.gitignore
/vendor /.php_cs.cache
Composer
在composer.json
文件中添加以下脚本
(...) "scripts": { (...) "cs": [ "php-cs-fixer fix --config=.php_cs -v", "php-cs-fixer fix --config=.phpspec_cs -v" ] },
Travis
更新您的.travis.yml
以缓存php_cs.cache
文件
cache: directories: - $HOME/.php-cs-fixer
然后在script
部分运行php-cs-fixer
script: - vendor/bin/php-cs-fixer fix --config=.php_cs --verbose --diff --dry-run - vendor/bin/php-cs-fixer fix --config=.phpspec_cs --verbose --diff --dry-run
修复问题
手动
如果您需要本地修复问题,并且之前添加了composer脚本,只需运行
$ composer run-script cs
否则您可以运行
$ vendor/bin/php-cs-fixer fix -v $ vendor/bin/php-cs-fixer fix -v --config=.phpspec_cs