narrowspark / php-cs-fixer-config
Provides a configuration for friendsofphp/php-cs-fixer, used within Narrowspark and Anolilab.
Fund package maintenance!
prisis
Installs: 58 623
Dependents: 5
Suggesters: 0
Security: 0
Stars: 4
Watchers: 1
Forks: 2
Open Issues: 32
Requires
- php: ^7.3
- ergebnis/license: ~0.1.0
- friendsofphp/php-cs-fixer: ~2.16.3
- kubawerlos/php-cs-fixer-custom-fixers: ~2.2.0
- pedrotroller/php-cs-custom-fixer: ~2.21.0
Requires (Dev)
- ext-json: *
- narrowspark/testing-helper: ^8.0.2
- phpunit/phpunit: ^8.5.4
- dev-master
- 6.2.0
- 6.1.0
- 6.0.0
- 5.3.0
- 5.2.0
- 5.1.1
- 5.1.0
- 5.0.0
- 4.1.0
- 4.0.0
- 3.5.0
- 3.4.0
- 3.3.0
- 3.2.0
- 3.1.2
- v3.1.1
- v3.1.0
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.1.0
- v2.0.4
- v2.0.3
- v2.0.2
- v2.0.1
- v2.0.0
- v1.4.1
- v1.4.0
- v1.3.0
- v1.2.0
- v1.1.5
- v1.1.4
- v1.1.3
- v1.1.2
- v1.1.1
- v1.1.0
- v1.0.0
- dev-dependabot/composer/dot-build/wikimedia/composer-merge-plugin-tw-2.0.1
- dev-dependabot/composer/dot-build/infection/infection-tw-0.21.1
- dev-dependabot/composer/dot-build/phpstan/phpstan-tw-0.12.78
- dev-dependabot/npm_and_yarn/lodash-4.17.21
- dev-dependabot/npm_and_yarn/write-good-1.0.8
- dev-dependabot/composer/dot-build/felixfbecker/advanced-json-rpc-tw-3.2.0
- dev-dependabot/composer/dot-build/vimeo/psalm-tw-3.18.2
- dev-dependabot/composer/dot-build/psalm/plugin-phpunit-tw-0.12.2
- dev-dependabot/composer/dot-build/jwage/changelog-generator-tw-1.3.0
- dev-dependabot/composer/dot-build/phpstan/phpstan-strict-rules-tw-0.12.9
- dev-dependabot/composer/dot-build/phpstan/phpstan-mockery-tw-0.12.12
- dev-dependabot/npm_and_yarn/textlint-11.8.2
- dev-dependabot/composer/friendsofphp/php-cs-fixer-approx-2.18.2
- dev-dependabot/npm_and_yarn/textlint-rule-terminology-2.1.5
- dev-dependabot/composer/dot-build/phpstan/phpstan-phpunit-tw-0.12.17
- dev-dependabot/composer/dot-build/phpstan/phpstan-deprecation-rules-tw-0.12.6
- dev-dependabot/npm_and_yarn/ini-1.3.8
- dev-dependabot/npm_and_yarn/ini-1.3.7
- dev-dependabot/composer/dot-build/slam/phpstan-extensions-tw-5.1.0
- dev-dependabot/npm_and_yarn/textlint-rule-en-capitalization-2.0.3
- dev-dependabot/composer/pedrotroller/php-cs-custom-fixer-approx-2.23.1
- dev-dependabot/npm_and_yarn/node-fetch-2.6.1
- dev-dependabot/composer/dot-build/thecodingmachine/phpstan-strict-rules-tw-0.12.1
- dev-dependabot/composer/ergebnis/license-approx-1.1.0
- dev-dependabot/npm_and_yarn/textlint-rule-alex-3.0.0
- dev-dependabot/composer/dot-build/rector/rector-tw-0.7.65
- dev-dependabot/npm_and_yarn/dot-prop-4.2.1
- dev-renovate/configure
- dev-dependabot/composer/kubawerlos/php-cs-fixer-custom-fixers-approx-2.3.0
- dev-dependabot/npm_and_yarn/textlint-rule-no-dead-link-4.7.0
- dev-dependabot/composer/phpunit/phpunit-tw-8.5.5
This package is auto-updated.
Last update: 2021-02-24 07:08:35 UTC
README
This repository provides a configuration for https://github.com/FriendsOfPHP/PHP-CS-Fixer, which we use to verify and enforce a single coding standard for PHP code within Narrowspark and Anolilab.Installation
Via Composer
$ composer require narrowspark/php-cs-fixer-config
Usage
Create a configuration file .php_cs
in the root of your project:
<?php declare(strict_types=1); use Narrowspark\CS\Config\Config; $config = new Config(); $config->getFinder() ->files() ->in(__DIR__) ->exclude('.build') ->exclude('vendor') ->name('*.php') ->ignoreDotFiles(true) ->ignoreVCS(true); $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 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 declare(strict_types=1); use Narrowspark\CS\Config\Config; +$header = <<<EOF +Copyright (c) 2020 Narrowspark + +For the full copyright and license information, please view +the LICENSE file that was distributed with this source code. +EOF; -$config = new Narrowspark\CS\Config\Config(); +$config = new Narrowspark\CS\Config\Config($header); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache'); return $config;
This will turn on and configure the HeaderCommentFixer
, so that
file headers will be added to PHP files, for example:
Configuration with override rules
💡 optionally override rules from a rule set by passing in an array of rules to be merged in:
<?php declare(strict_types=1); use Narrowspark\CS\Config\Config; - $config = new Config(); + $config = new Config(null /* if you dont need a header */, [ 'mb_str_functions' => false, 'strict_comparison' => false, ]); $config->getFinder() ->files() ->in(__DIR__) ->exclude('.build') ->exclude('vendor') ->name('*.php') ->ignoreDotFiles(true) ->ignoreVCS(true); $config->setCacheFile(__DIR__ . '/.build/php-cs-fixer/php_cs.cache'); return $config;
Composer
If you like composer
scripts, add a coding-standards
script to composer.json
:
{ "name": "foo/bar", "require": { "php": "^7.3", }, "require-dev": { "narrowspark/php-cs-fixer-config": "~1.0.0" + }, + "scripts": { + "cs:check": [ + "mkdir -p .build/php-cs-fixer", + "php-cs-fixer fix --diff --diff-format=udiff --verbose" + ] } }
Run
$ composer cs:check
To automatically fix coding standard violations.
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.3 + + 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
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.3 --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.3-composer-locked-${{ hashFiles('**/composer.lock') }} + restore-keys: | + php7.3-composer-locked- + + - name: "Install locked dependencies with composer" + run: php7.3 $(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.3-php-cs-fixer-${{ hashFiles('**/composer.lock') }} + restore-keys: | + php7.3-php-cs-fixer- + + - name: "Run friendsofphp/php-cs-fixer" + run: php7.3 vendor/bin/php-cs-fixer fix --config=.php_cs --diff --diff-format=udiff --dry-run --verbose
Testing
$ vendor/bin/phpunit
Contributing
If you would like to help take a look at the list of issues and check our Contributing guild.
Note: please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms.
Credits
License
The Narrowspark http-emitter is open-sourced software licensed under the MIT license