netgen / layouts-coding-standard

Netgen Layouts 编码规范

2.1.3 2024-01-08 13:43 UTC

This package is auto-updated.

Last update: 2024-09-08 15:23:53 UTC


README

此存储库提供所有 Netgen Layouts 项目的默认配置,用于检查编码规范违规。配置基于 PHP CS Fixer。

安装

$ composer require --dev netgen/layouts-coding-standard

使用方法

在项目根目录下创建一个 .php-cs-fixer.php 文件,内容如下

return (new Netgen\Layouts\CodingStandard\PhpCsFixer\Config())
    ->setFinder(
        PhpCsFixer\Finder::create()
            ->exclude(['vendor'])
            ->in(__DIR__)
    )
;

使用以下命令运行修复器

$ vendor/bin/php-cs-fixer fix

覆盖现有规则

您可以按项目覆盖此配置中包含的规则

return (new Netgen\Layouts\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/netgen/layouts-coding-standard/lib/PhpCsFixer/Config.php';

例如,如果您希望通过 GitHub Action 运行 PHP CS Fixer,而不需要运行 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@v3
      - uses: actions/checkout@v3
        with:
          repository: netgen-layouts/layouts-coding-standard
          path: vendor/netgen/layouts-coding-standard
      - name: PHP CS Fixer
        uses: docker://oskarstark/php-cs-fixer-ga
        with:
          args: --diff --dry-run

有关更多详细信息,请查看https://github.com/OskarStark/php-cs-fixer-ga