localheinz / php-cs-fixer-config
Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer.
Installs: 48 641
Dependents: 3
Suggesters: 0
Security: 0
Stars: 22
Watchers: 2
Forks: 1
Open Issues: 0
Requires
- php: ^7.1
- friendsofphp/php-cs-fixer: ~2.16.0
Requires (Dev)
- localheinz/composer-normalize: ^1.3.1
- phpunit/phpunit: ^7.5.17
- dev-master
- 1.24.0
- 1.23.0
- 1.22.1
- 1.22.0
- 1.21.0
- 1.20.1
- 1.20.0
- 1.19.2
- 1.19.1
- 1.19.0
- 1.18.0
- 1.17.0
- 1.16.1
- 1.16.0
- 1.15.0
- 1.14.2
- 1.14.1
- 1.14.0
- 1.13.1
- 1.13.0
- 1.12.3
- 1.12.2
- 1.12.1
- 1.12.0
- 1.11.0
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.3
- 1.7.2
- 1.7.1
- 1.7.0
- 1.6.3
- 1.6.2
- 1.6.1
- 1.6.0
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.1
- 1.2.0
- 1.1.0
- 1.0.2
- 1.0.1
- 1.0.0
- dev-fix/abandon
This package is auto-updated.
Last update: 2019-11-26 10:11:45 UTC
README
Use ergebnis/php-cs-fixer-config
instead.
php-cs-fixer-config
Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer
.
Installation
Run
$ composer require --dev localheinz/php-cs-fixer-config
Usage
Configuration
Pick one of the rule sets:
Localheinz\PhpCsFixer\RuleSet\Php71
Localheinz\PhpCsFixer\RuleSet\Php73
Create a configuration file .php_cs
in the root of your project:
<?php use Localheinz\PhpCsFixer\Config; $config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71()); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.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 Localheinz\PhpCsFixer\Config; +$header = <<<EOF +Copyright (c) 2017 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/localheinz/php-cs-fixer-config +EOF; -$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71()); +$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71($header)); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.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) 2017 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/localheinz/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 Localheinz\PhpCsFixer\Config; -$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71()); +$config = Config\Factory::fromRuleSet(new Config\RuleSet\Php71(), [ + 'mb_str_functions' => false, + 'strict_comparison' => false, +]); $config->getFinder()->in(__DIR__); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.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 --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": "^7.2", }, "require-dev": { "friendsofphp/php-cs-fixer": "~2.16.0" + }, + "scripts": { + "coding-standards": [ + "mkdir -p .build/php-cs-fixer", + "php-cs-fixer fix --diff --diff-format=udiff --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: push: branches: - master tags: - "**" name: "Continuous Integration" jobs: + coding-standards: + name: "Coding Standards" + + runs-on: ubuntu-latest + + steps: + - name: "Checkout" + uses: actions/checkout@v1.1.0 + + - name: "Disable Xdebug" + run: php7.2 --ini | grep xdebug | sed 's/,$//' | xargs sudo rm + + - name: "Cache dependencies installed with composer" + uses: actions/cache@v1.0.2 + with: + path: ~/.composer/cache + key: php7.2-composer-locked-${{ hashFiles('**/composer.lock') }} + restore-keys: | + php7.2-composer-locked- + + - name: "Install locked dependencies with composer" + run: php7.2 $(which composer) install --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@v1.0.2 + with: + path: ~/.build/php-cs-fixer + key: php7.2-php-cs-fixer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + php7.2-php-cs-fixer- + + - name: "Run friendsofphp/php-cs-fixer" + run: php7.2 vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose
Travis
If you like Travis CI, add a coding-standards
stage to your jobs:
language: php cache: directories: - $HOME/.composer/cache + - .build/php-cs-fixer jobs: include: + - stage: "Coding Standards" + + php: 7.2 + + install: + - composer install --no-interaction --no-progress --no-suggest + + before_script: + - mkdir -p .build/php-cs-fixer + + script: + - vendor/bin/php-cs-fixer fix --config=.php_cs --diff --dry-run --verbose
Changelog
Please have a look at CHANGELOG.md
.
Contributing
Please have a look at CONTRIBUTING.md
.
Code of Conduct
Please have a look at CODE_OF_CONDUCT.md
.
License
This package is licensed using the MIT License.
Credits
This project is inspired by refinery29/php-cs-fixer-config
, which I created and maintained from August 7, 2015 until May 29, 2017, while working for Refinery29, Inc.