wayofdev / cs-fixer-config
🧹 为PHP CS Fixer添加自定义规则集,以实现一致的编码标准。
Requires
- php: ^8.1
- friendsofphp/php-cs-fixer: ^3.57
Requires (Dev)
- ergebnis/phpunit-slow-test-detector: ^2.14
- pestphp/pest: ^2.34
- phpstan/extension-installer: ^1.3
- phpstan/phpstan: ^1.11
- phpstan/phpstan-deprecation-rules: ^1.2
- phpstan/phpstan-phpunit: ^1.4
- phpstan/phpstan-strict-rules: ^1.6
- phpunit/phpunit: ^10.5
- psalm/plugin-phpunit: ^0.19
- rector/rector: ^1.1
- roave/infection-static-analysis-plugin: ^1.35
- vimeo/psalm: ^5.24
- dev-master
- v1.5.3
- v1.5.2
- v1.5.1
- v1.5.0
- v1.4.5
- v1.4.4
- v1.4.3
- v1.4.2
- v1.4.1
- v1.4.0
- v1.3.1
- v1.3.0
- v1.2.61
- v1.2.60
- v1.2.59
- v1.2.58
- v1.2.57
- v1.2.56
- v1.2.55
- v1.2.54
- v1.2.53
- v1.2.52
- v1.2.51
- v1.2.50
- v1.2.49
- v1.2.48
- v1.2.47
- v1.2.46
- v1.2.45
- v1.2.44
- v1.2.43
- v1.2.42
- v1.2.41
- v1.2.40
- v1.2.39
- v1.2.38
- v1.2.37
- v1.2.36
- v1.2.35
- v1.2.34
- v1.2.33
- v1.2.32
- v1.2.31
- v1.2.30
- v1.2.29
- v1.2.28
- v1.2.27
- v1.2.26
- v1.2.25
- v1.2.24
- v1.2.23
- v1.2.22
- v1.2.21
- v1.2.20
- v1.2.19
- v1.2.18
- v1.2.17
- v1.2.16
- v1.2.15
- v1.2.14
- v1.2.13
- v1.2.12
- v1.2.11
- v1.2.10
- v1.2.9
- v1.2.8
- v1.2.7
- v1.2.6
- v1.2.5
- v1.2.4
- v1.2.3
- v1.2.2
- v1.2.1
- v1.2.0
- v1.1.19
- v1.1.18
- v1.1.17
- v1.1.16
- v1.1.15
- v1.1.14
- v1.1.13
- v1.1.12
- v1.1.11
- v1.1.10
- v1.1.9
- v1.1.8
- v1.1.7
- v1.1.6
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.2
- v1.0.1
- v1.0.0
- dev-renovate/vimeo-psalm-5.x-lockfile
- dev-renovate/pestphp-pest-2.x-lockfile
- dev-renovate/phpstan-packages
- dev-renovate/pestphp-pest-3.x
- dev-renovate/wayofdev-gh-actions-3.x
- dev-renovate/wagoid-commitlint-github-action-6.x
- dev-renovate/ergebnis-phpunit-slow-test-detector-2.x-lockfile
- dev-renovate/friendsofphp-php-cs-fixer-3.x-lockfile
- dev-renovate/rector-rector-1.x-lockfile
- dev-renovate/shivammathur-setup-php-2.x
- dev-release-please--branches--master--components--php-cs-fixer-config
- dev-feat/auto-merge
- dev-codesee-arch-diagram-workflow-1678375134679
This package is auto-updated.
Last update: 2024-09-20 14:43:25 UTC
README
PHP CS Fixer Config
PHP-CS-Fixer包的包装器,包含预定义的规则 - 一个用于自动修复PHP编码标准问题的工具。
此存储库旨在为多个项目提供一种标准化的方法来应用编码标准,确保一致性和遵循最佳实践。通过使用预定义的规则集,它简化了设置过程,并允许团队快速将PHP-CS-Fixer集成到其开发工作流程中。
如果您喜欢/使用此包,请考虑⭐️ 星标它。谢谢!
📜 自定义规则集
WayOfDev\PhpCsFixer\Config\RuleSets\DefaultRuleset::class
基于@Symfony
规则集
- 由
@wayofdev
组织使用
WayOfDev\PhpCsFixer\Config\RuleSets\ExtendedPERSet::class
基于@PER-CS2.0
规则集
- 由
@buggregator
和@cycle
组织使用
💿 安装
→ 使用composer
作为依赖项要求
composer req --dev wayofdev/cs-fixer-config
🛠 配置
→ 设置
-
创建一个PHP文件,命名为
.php-cs-fixer.dist.php
并将其放置在项目根目录中。它将被PHP CS Fixer自动识别。 -
.php-cs-fixer.dist.php
文件的示例内容<?php declare(strict_types=1); use WayOfDev\PhpCsFixer\Config\ConfigBuilder; use WayOfDev\PhpCsFixer\Config\RuleSets\DefaultSet; require_once 'vendor/autoload.php'; $config = ConfigBuilder::createFromRuleSet(new DefaultSet()) ->inDir(__DIR__ . '/src') ->inDir(__DIR__ . '/tests') ->addFiles([__FILE__]) ->getConfig() ; $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php-cs-fixer.cache'); return $config;
→ Composer脚本
-
将
scripts
部分添加到composer.json
{ "scripts": { + "cs:diff": "php vendor/bin/php-cs-fixer fix --dry-run -v --diff", + "cs:fix": "php vendor/bin/php-cs-fixer fix -v" } }
→ Git
-
将
.build
文件夹文件放入.gitignore
+/.build/ /vendor/
→ Makefile
-
如果您正在使用
Makefile
,创建一个带有lint-php
和lint-diff
目标的Makefile
+APP_RUNNER ?= php +APP_COMPOSER ?= $(APP_RUNNER) composer + +prepare: + mkdir -p .build/php-cs-fixer +.PHONY: prepare +lint-php: prepare ## Fixes code to follow coding standards using php-cs-fixer + $(APP_COMPOSER) cs:fix +.PHONY: lint-php +lint-diff: prepare ## Runs php-cs-fixer in dry-run mode and shows diff which will by applied + $(APP_COMPOSER) cs:diff +.PHONY: lint-diff
或者,您可以从以下任何一个存储库检查我们预配置的Makefile
https://github.com/wayofdev/php-cs-fixer-config/blob/master/Makefile
https://github.com/wayofdev/laravel-package-tpl/blob/master/Makefile
→ GitHub Actions
-
要在GitHub Actions中使用此包,请向您的存储库添加一个
coding-standards.yml
工作流程--- on: # yamllint disable-line rule:truthy pull_request: branches: - master push: branches: - master name: 🧹 Fix PHP coding standards jobs: coding-standards: timeout-minutes: 4 runs-on: ${{ matrix.os }} concurrency: cancel-in-progress: true group: coding-standards-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} strategy: matrix: os: - ubuntu-latest php-version: - '8.1' dependencies: - locked permissions: contents: write steps: - name: ⚙️ Set git to use LF line endings run: | git config --global core.autocrlf false git config --global core.eol lf - name: 🛠️ Setup PHP uses: shivammathur/[email protected] with: php-version: ${{ matrix.php-version }} extensions: none, ctype, dom, json, mbstring, phar, simplexml, tokenizer, xml, xmlwriter ini-values: error_reporting=E_ALL coverage: none - name: 📦 Check out the codebase uses: actions/[email protected] - name: 🛠️ Setup problem matchers run: | echo "::add-matcher::${{ runner.tool_cache }}/php.json" - name: 🤖 Validate composer.json and composer.lock run: composer validate --ansi --strict - name: 🔍 Get composer cache directory uses: wayofdev/gh-actions/actions/composer/[email protected] - name: ♻️ Restore cached dependencies installed with composer uses: actions/[email protected] with: path: ${{ env.COMPOSER_CACHE_DIR }} key: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}-${{ hashFiles('composer.lock') }} restore-keys: php-${{ matrix.php-version }}-composer-${{ matrix.dependencies }}- - name: 📥 Install "${{ matrix.dependencies }}" dependencies with composer uses: wayofdev/gh-actions/actions/composer/[email protected] with: dependencies: ${{ matrix.dependencies }} - name: 🛠️ Prepare environment run: make prepare - name: 🚨 Run coding standards task run: composer cs:fix env: PHP_CS_FIXER_IGNORE_ENV: true - name: 📤 Commit and push changed files back to GitHub uses: stefanzweifel/[email protected] with: commit_message: 'style(php-cs-fixer): lint php files and fix coding standards' branch: ${{ github.head_ref }} commit_author: 'github-actions <[email protected]>' env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
或者,您可以从以下任何一个存储库检查我们预配置的工作流程
https://github.com/wayofdev/php-cs-fixer-config/blob/master/.github/workflows/coding-standards.yml
💻 使用方法
通过简单地运行控制台命令来修复编码标准
→ 直接
vendor/bin/php-cs-fixer fix -v
→ 通过Composer脚本
要使用Composer脚本命令
-
使用php-cs-fixer修复代码以符合编码标准
composer cs:diff
-
以干运行模式运行php-cs-fixer并显示将要应用的差异
composer cs:fix
→ 使用Makefile
要使用Makefile
-
使用php-cs-fixer修复代码以符合编码标准
make lint-php
-
以干运行模式运行php-cs-fixer并显示将要应用的差异
make lint-diff
🔒 安全策略
此项目有一个安全策略。
🙌 想要贡献?
感谢您考虑为wayofdev社区做出贡献!我们欢迎所有类型的贡献。如果您想
非常欢迎您的参与。在贡献之前,请查阅我们的贡献指南。
🫡 贡献者
🌐 社交链接
🧱 资源
-
所有修复器的完整文档在此处可查 - PHP-CS-Fixer 配置 UI