marioblazek / coding-standard
我的个人编码标准
v1.0.1
2022-09-08 18:51 UTC
Requires
- php: ^7.4 || ^8.0
- friendsofphp/php-cs-fixer: ^3.0
Requires (Dev)
- phpstan/phpstan: ^1.1
- phpstan/phpstan-strict-rules: ^1.0
README
此仓库提供了一个默认的编码标准配置。该配置基于PHP CS Fixer,并受到Netgen Layouts编码标准的影响。
安装
$ composer require --dev marioblazek/coding-standard
可用的规则列表可在以下位置找到:这里。
使用方法
在项目根目录创建一个.php-cs-fixer.php
文件,内容如下
return (new Marek\CodingStandard\PhpCsFixer\Config()) ->setFinder( PhpCsFixer\Finder::create() ->exclude(['vendor']) ->in(__DIR__) ) ;
使用以下命令运行修复器
$ vendor/bin/php-cs-fixer fix
覆盖现有规则
您可以通过项目覆盖此配置中包含的规则
return (new Marek\CodingStandard\PhpCsFixer\Config()) ->addRules([ 'list_syntax' => ['syntax' => 'long'], ]) ->setFinder( PhpCsFixer\Finder::create() ->exclude(['vendor']) ->in(__DIR__) ) ;
支持PHP CS Fixer的PHAR分发
您还可以通过在.php-cs-fixer.php
文件顶部添加以下内容来支持运行PHP CS Fixer的PHAR版本
// To support running PHP CS Fixer via PHAR file (e.g. in GitHub Actions) require_once __DIR__ . '/vendor/marioblazek/coding-standard/src/PhpCsFixer/Config.php';
这在使用GitHub action时非常有用,因为它不需要运行composer install
# .github/workflows/ci.yml name: PHP CS Fixer on: [push, pull_request] jobs: php-cs-fixer: name: PHP CS Fixer runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - uses: actions/checkout@v2 with: repository: marioblazek/coding-standard path: vendor/marioblazek/coding-standard - name: PHP CS Fixer uses: OskarStark/php-cs-fixer-ga@master with: args: --diff --dry-run
有关更多详细信息,请参阅https://github.com/OskarStark/php-cs-fixer-ga。
变更日志
变更日志可在以下位置找到:这里。