ergebnis/php-cs-fixer-config
Composer 安装命令:
composer require ergebnis/php-cs-fixer-config
包简介
Provides a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
README 文档
README
This project provides a composer package with a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
Installation
Run
composer require --dev ergebnis/php-cs-fixer-config
Usage
Configuration
Pick one of the rule sets:
Ergebnis\PhpCsFixer\RuleSet\Php53Ergebnis\PhpCsFixer\RuleSet\Php54Ergebnis\PhpCsFixer\RuleSet\Php55Ergebnis\PhpCsFixer\RuleSet\Php56Ergebnis\PhpCsFixer\RuleSet\Php70Ergebnis\PhpCsFixer\RuleSet\Php71Ergebnis\PhpCsFixer\RuleSet\Php72Ergebnis\PhpCsFixer\RuleSet\Php73Ergebnis\PhpCsFixer\RuleSet\Php74Ergebnis\PhpCsFixer\RuleSet\Php80Ergebnis\PhpCsFixer\RuleSet\Php81Ergebnis\PhpCsFixer\RuleSet\Php82Ergebnis\PhpCsFixer\RuleSet\Php83Ergebnis\PhpCsFixer\RuleSet\Php84Ergebnis\PhpCsFixer\RuleSet\Php85
Create a configuration file .php-cs-fixer.php in the root of your project:
<?php declare(strict_types=1); use Ergebnis\PhpCsFixer\Config; use PhpCsFixer\Finder; $ruleSet = Config\RuleSet\Php83::create(); $finder = Finder::create()->in(__DIR__); $config = Config\Factory::fromRuleSet($ruleSet); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); $config->setFinder($finder); return $config;
Git
All configuration examples use the caching feature, and if you want to use it as well, you should add the cache directory to .gitignore:
+ /.build/
/vendor/
Configuring a rule set with header
💡 Optionally specify a header:
<?php declare(strict_types=1); use Ergebnis\PhpCsFixer\Config; use PhpCsFixer\Finder; +$header = <<<EOF +Copyright (c) 2023 Andreas Möller + +For the full copyright and license information, please view +the LICENSE file that was distributed with this source code. + +@see https://github.com/ergebnis/php-cs-fixer-config +EOF; -$ruleSet = Config\RuleSet\Php83::create(); +$ruleSet = Config\RuleSet\Php83::create()->withHeader($header); $finder = Finder::create()->in(__DIR__); $config = Config\Factory::fromRuleSet($ruleSet); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); $config->setFinder($finder); return $config;
This will enable and configure the HeaderCommentFixer, so that file headers will be added to PHP files, for example:
<?php declare(strict_types=1); +/** + * Copyright (c) 2023 Andreas Möller + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + * + * @see https://github.com/ergebnis/php-cs-fixer-config + */
Configuring a rule set that overrides rules
💡 Optionally override rules from a rule set by passing a set of rules to be merged in:
<?php declare(strict_types=1); use Ergebnis\PhpCsFixer\Config; use PhpCsFixer\Finder; -$ruleSet = Config\RuleSet\Php83::create(); +$ruleSet = Config\RuleSet\Php83::create()->withRules(Config\Rules::fromArray([ + 'mb_str_functions' => false, + 'strict_comparison' => false, +])); $finder = Finder::create()->in(__DIR__); $config = Config\Factory::fromRuleSet($ruleSet); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); $config->setFinder($finder); return $config;
Configuring a rule set that registers and configures rules for custom fixers
💡 Optionally register and configure rules for custom fixers:
<?php declare(strict_types=1); use Ergebnis\PhpCsFixer\Config; use FooBar\Fixer; use PhpCsFixer\Finder; -$ruleSet = Config\RuleSet\Php83::create(); +$ruleSet = Config\RuleSet\Php83::create() + ->withCustomFixers(Config\Fixers::fromFixers( + new Fixer\BarBazFixer(), + new Fixer\QuzFixer(), + )) + ->withRules(Config\Rules::fromArray([ + 'FooBar/bar_baz' => true, + 'FooBar/quz' => [ + 'qux => false, + ], + ])) +]); $finder = Finder::create()->in(__DIR__); $config = Config\Factory::fromRuleSet($ruleSet); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); $config->setFinder($finder); return $config;
Makefile
If you like Makefiles, create a Makefile with a coding-standards target:
+.PHONY: coding-standards +coding-standards: vendor + mkdir -p .build/php-cs-fixer + vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.php --diff --show-progress=dots --verbose vendor: composer.json composer.lock composer validate composer install
Run
make coding-standards
to automatically fix coding standard violations.
Composer script
If you like composer scripts, add a coding-standards script to composer.json:
{
"name": "foo/bar",
"require": {
"php": "^8.1",
},
"require-dev": {
"ergebnis/php-cs-fixer-config": "^6.21.0"
+ },
+ "scripts": {
+ "coding-standards": [
+ "mkdir -p .build/php-cs-fixer",
+ "php-cs-fixer fix --diff --show-progress=dots --verbose"
+ ]
}
}
Run
composer coding-standards
to automatically fix coding standard violations.
GitHub Actions
If you like GitHub Actions, add a coding-standards job to your workflow:
on:
pull_request: null
push:
branches:
- main
name: "Integrate"
jobs:
+ coding-standards:
+ name: "Coding Standards"
+
+ runs-on: ubuntu-latest
+
+ strategy:
+ matrix:
+ php-version:
+ - "8.1"
+
+ steps:
+ - name: "Checkout"
+ uses: "actions/checkout@v2"
+
+ - name: "Set up PHP"
+ uses: "shivammathur/setup-php@v2"
+ with:
+ coverage: "none"
+ php-version: "${{ matrix.php-version }}"
+
+ - name: "Cache dependencies installed with composer"
+ uses: "actions/cache@v2"
+ with:
+ path: "~/.composer/cache"
+ key: "php-${{ matrix.php-version }}-composer-${{ hashFiles('composer.lock') }}"
+ restore-keys: "php-${{ matrix.php-version }}-composer-"
+
+ - name: "Install locked dependencies with composer"
+ run: "composer install --ansi --no-interaction --no-progress --no-suggest"
+
+ - name: "Create cache directory for friendsofphp/php-cs-fixer"
+ run: mkdir -p .build/php-cs-fixer
+
+ - name: "Cache cache directory for friendsofphp/php-cs-fixer"
+ uses: "actions/cache@v2"
+ with:
+ path: "~/.build/php-cs-fixer"
+ key: "php-${{ matrix.php-version }}-php-cs-fixer-${{ github.ref_name }}"
+ restore-keys: |
+ php-${{ matrix.php-version }}-php-cs-fixer-main
+ php-${{ matrix.php-version }}-php-cs-fixer-
+
+ - name: "Run friendsofphp/php-cs-fixer"
+ run: "vendor/bin/php-cs-fixer fix --ansi --config=.php-cs-fixer.php --diff --dry-run --show-progress=dots --verbose"
Changelog
The maintainers of this project record notable changes to this project in a changelog.
Contributing
The maintainers of this project suggest following the contribution guide.
Code of Conduct
The maintainers of this project ask contributors to follow the code of conduct.
General Support Policy
The maintainers of this project provide limited support.
You can support the maintenance of this project by sponsoring @ergebnis.
PHP Version Support Policy
This project currently supports the following PHP versions:
- PHP 7.4 (has reached its end of life on November 28, 2022)
- PHP 8.0 (has reached its end of life on November 26, 2023)
- PHP 8.1 (has reached its end of life on December 31, 2025)
- PHP 8.2
- PHP 8.3
- PHP 8.4
- PHP 8.5
The maintainers of this project add support for a PHP version following its initial release and may drop support for a PHP version when it has reached its end of life.
Security Policy
This project has a security policy.
License
This project uses the MIT license.
Credits
This project is inspired by and also replaces localheinz/php-cs-fixer-config.
This project requires and enables custom fixers from the following packages:
Social
Follow @localheinz and @ergebnis on Twitter.
ergebnis/php-cs-fixer-config 适用场景与选型建议
ergebnis/php-cs-fixer-config 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3.04M 次下载、GitHub Stars 达 70, 最近一次更新时间为 2019 年 11 月 25 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 ergebnis/php-cs-fixer-config 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ergebnis/php-cs-fixer-config 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 3.04M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 70
- 点击次数: 37
- 依赖项目数: 184
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-11-25