ergebnis / php-cs-fixer-config
Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer.
Installs: 890 842
Dependents: 72
Suggesters: 0
Security: 0
Stars: 38
Watchers: 2
Forks: 10
Open Issues: 0
Requires
- php: ~8.0.0 || ~8.1.0 || ~8.2.0
- ext-filter: *
- friendsofphp/php-cs-fixer: ~3.14.3
Requires (Dev)
- ergebnis/composer-normalize: ^2.29.0
- ergebnis/license: ^2.1.0
- fakerphp/faker: ^1.21.0
- infection/infection: ~0.26.18
- phpunit/phpunit: ^9.5.28
- psalm/plugin-phpunit: ~0.18.4
- rector/rector: ~0.15.10
- symfony/filesystem: ^5.0.0 || ^6.0.0
- symfony/process: ^5.0.0 || ^6.0.0
- vimeo/psalm: ^5.6.0
- dev-main
- 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/rector/rector-0.15.13
- dev-dependabot/composer/phpunit/phpunit-9.6.3
- dev-dependabot/composer/rector/rector-0.15.12
- dev-dependabot/composer/infection/infection-0.26.19
This package is auto-updated.
Last update: 2023-02-07 13:02:52 UTC
README
Provides a configuration factory and multiple rule sets 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\Php80
Ergebnis\PhpCsFixer\RuleSet\Php81
Ergebnis\PhpCsFixer\RuleSet\Php82
Create a configuration file .php-cs-fixer.php
in the root of your project:
<?php use Ergebnis\PhpCsFixer\Config; $config = Config\Factory::fromRuleSet(new Config\RuleSet\Php80()); $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/
💡 Personally, I prefer to use a .build
directory for storing build artifacts.
Configuration with header
💡 Optionally specify a header:
<?php use Ergebnis\PhpCsFixer\Config; +$header = <<<EOF +Copyright (c) 2020 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; -$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php80()); +$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php80($header)); $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 /** * Copyright (c) 2020 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 */
Configuration with override rules
💡 Optionally override rules from a rule set by passing in an array of rules to be merged in:
<?php use Ergebnis\PhpCsFixer\Config; -$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php80()); +$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php80(), [ + 'mb_str_functions' => false, + 'strict_comparison' => false, +]); $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 --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.0", }, "require-dev": { "ergebnis/php-cs-fixer-config": "~5.1.0" + }, + "scripts": { + "coding-standards": [ + "mkdir -p .build/php-cs-fixer", + "php-cs-fixer fix --diff --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.0" + + 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 --verbose"
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
💡 Do you want to add a rule for personal use or use in your organization? Instead of opening a pull request here, perhaps consider creating a new package based on ergebnis/php-cs-fixer-config-template
, a GitHub repository template that provides a good starting point for creating and sharing your own rule sets.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Please have a look at LICENSE.md
.
Credits
This project is inspired by and also replaces localheinz/php-cs-fixer-config
.
Curious what I am up to?
Follow me on Twitter!