ergebnis / php-cs-fixer-config
Provides a configuration factory and rule set factories for friendsofphp/php-cs-fixer.
Installs: 1 839 341
Dependents: 131
Suggesters: 0
Security: 0
Stars: 68
Watchers: 3
Forks: 13
Open Issues: 2
Requires
- php: ~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0
- ext-filter: *
- erickskrauch/php-cs-fixer-custom-fixers: ~1.3.0
- friendsofphp/php-cs-fixer: ~3.65.0
- kubawerlos/php-cs-fixer-custom-fixers: ~3.22.0
Requires (Dev)
- ergebnis/composer-normalize: ^2.44.0
- ergebnis/data-provider: ^3.4.0
- ergebnis/license: ^2.6.0
- ergebnis/phpunit-slow-test-detector: ^2.16.1
- ergebnis/rector-rules: ^1.2.0
- fakerphp/faker: ^1.24.1
- phpstan/extension-installer: ^1.4.3
- phpstan/phpstan: ^1.12.11
- phpstan/phpstan-deprecation-rules: ^1.2.1
- phpstan/phpstan-phpunit: ^1.4.1
- phpstan/phpstan-strict-rules: ^1.6.1
- phpunit/phpunit: ^9.6.21
- rector/rector: ^1.2.10
- symfony/filesystem: ^5.0.0 || ^6.0.0
- symfony/process: ^5.0.0 || ^6.0.0
- dev-main
- 6.39.0
- 6.38.0
- 6.37.0
- 6.36.0
- 6.35.0
- 6.34.0
- 6.33.0
- 6.32.0
- 6.31.0
- 6.30.1
- 6.30.0
- 6.29.0
- 6.28.1
- 6.28.0
- 6.27.0
- 6.26.0
- 6.25.1
- 6.25.0
- 6.24.0
- 6.23.0
- 6.22.0
- 6.21.0
- 6.20.0
- 6.19.0
- 6.18.0
- 6.17.0
- 6.16.1
- 6.16.0
- 6.15.0
- 6.14.0
- 6.13.1
- 6.13.0
- 6.12.0
- 6.11.0
- 6.10.0
- 6.9.0
- 6.8.1
- 6.8.0
- 6.7.0
- 6.6.0
- 6.5.0
- 6.4.0
- 6.3.0
- 6.2.0
- 6.1.0
- 6.0.0
- 5.16.0
- 5.15.1
- 5.15.0
- 5.14.2
- 5.14.1
- 5.14.0
- 5.13.0
- 5.12.0
- 5.11.1
- 5.11.0
- 5.10.0
- 5.9.2
- 5.9.1
- 5.9.0
- 5.8.0
- 5.7.0
- 5.6.0
- 5.5.2
- 5.5.1
- 5.5.0
- 5.4.0
- 5.3.3
- 5.3.2
- 5.3.1
- 5.3.0
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.1
- 5.0.0
- 4.11.0
- 4.10.0
- 4.9.0
- 4.8.0
- 4.7.0
- 4.6.0
- 4.5.3
- 4.5.2
- 4.5.1
- 4.5.0
- 4.4.0
- 4.3.0
- 4.2.0
- 4.1.0
- 4.0.0
- 3.4.0
- 3.3.0
- 3.2.1
- 3.2.0
- 3.1.0
- 3.0.2
- 3.0.1
- 3.0.0
- 2.14.0
- 2.13.1
- 2.13.0
- 2.12.1
- 2.12.0
- 2.11.0
- 2.10.0
- 2.9.0
- 2.8.0
- 2.7.0
- 2.6.1
- 2.6.0
- 2.5.3
- 2.5.2
- 2.5.1
- 2.5.0
- 2.4.0
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.0
- dev-dependabot/composer/ergebnis/phpunit-slow-test-detector-2.17.0
- dev-feature/php-cs-fixer
- dev-feature/php84
- dev-feature/synchronize
- dev-dependabot/composer/ergebnis/rector-rules-1.2.0
This package is auto-updated.
Last update: 2024-11-25 13:25:13 UTC
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\Php53
Ergebnis\PhpCsFixer\RuleSet\Php54
Ergebnis\PhpCsFixer\RuleSet\Php55
Ergebnis\PhpCsFixer\RuleSet\Php56
Ergebnis\PhpCsFixer\RuleSet\Php70
Ergebnis\PhpCsFixer\RuleSet\Php71
Ergebnis\PhpCsFixer\RuleSet\Php72
Ergebnis\PhpCsFixer\RuleSet\Php73
Ergebnis\PhpCsFixer\RuleSet\Php74
Ergebnis\PhpCsFixer\RuleSet\Php80
Ergebnis\PhpCsFixer\RuleSet\Php81
Ergebnis\PhpCsFixer\RuleSet\Php82
Ergebnis\PhpCsFixer\RuleSet\Php83
Ergebnis\PhpCsFixer\RuleSet\Php84
Create a configuration file .php-cs-fixer.php
in the root of your project:
<?php declare(strict_types=1); use Ergebnis\PhpCsFixer\Config; $ruleSet = Config\RuleSet\Php83::create(); $config = Config\Factory::fromRuleSet($ruleSet); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); 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; +$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); $config = Config\Factory::fromRuleSet($ruleSet); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); 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; -$ruleSet = Config\RuleSet\Php83::create(); +$ruleSet = Config\RuleSet\Php83::create()->withRules(Config\Rules::fromArray([ + 'mb_str_functions' => false, + 'strict_comparison' => false, +])); $config = Config\Factory::fromRuleSet($ruleSet); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); 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; -$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, + ], + ])) +]); $config = Config\Factory::fromRuleSet($ruleSet); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/.php-cs-fixer.cache'); return $config;
Makefile
If you like Makefile
s, 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 @localheinz or requesting an invoice for services related to this project.
PHP Version Support Policy
This project supports PHP versions with active and security support.
The maintainers of this project add support for a PHP version following its initial release and drop support for a PHP version when it has reached the end of security support.
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.