visual-craft / php-cs-fixer-config
Configuration for friendsofphp/php-cs-fixer
Installs: 13 716
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 1
Open Issues: 0
Requires
- php: ^7.4 || ^8.0
- friendsofphp/php-cs-fixer: ^3.34
- kubawerlos/php-cs-fixer-custom-fixers: ^3.16
- pedrotroller/php-cs-custom-fixer: ^2.28
Requires (Dev)
- ergebnis/composer-normalize: ^2.25
- vimeo/psalm: ^4.22
README
Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer
.
Installation
Run
$ composer require --dev visual-craft/php-cs-fixer-config
Usage
Configuration
Pick one of the rule sets:
VisualCraft\PhpCsFixerConfig\RuleSet\Php74
VisualCraft\PhpCsFixerConfig\RuleSet\Php80
VisualCraft\PhpCsFixerConfig\RuleSet\Php81
VisualCraft\PhpCsFixerConfig\RuleSet\Php82
VisualCraft\PhpCsFixerConfig\RuleSet\Php83
Create a configuration file .php-cs-fixer.dist.php
in the root of your project:
<?php declare(strict_types=1); use VisualCraft\PhpCsFixerConfig; $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . '/src') ->append([ __DIR__ . '/.php-cs-fixer.dist.php', ]) ; $config = PhpCsFixerConfig\Factory::fromRuleSet(new PhpCsFixerConfig\RuleSet\Php83()); $config ->setFinder($finder) ->setCacheFile(__DIR__ . '/.php-cs-fixer.cache') ; return $config;
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 VisualCraft\PhpCsFixerConfig; $finder = PhpCsFixer\Finder::create() ->in(__DIR__ . '/src') ->append([ __DIR__ . '/.php-cs-fixer.dist.php', ]) ; -$config = PhpCsFixerConfig\Factory::fromRuleSet(new PhpCsFixerConfig\RuleSet\Php83()); +$config = PhpCsFixerConfig\Factory::fromRuleSet(new PhpCsFixerConfig\RuleSet\Php83(), [ + 'strict_comparison' => false, +]); $config ->setFinder($finder) ->setCacheFile(__DIR__ . '/.php-cs-fixer.cache') ; return $config;
Composer scripts
If you like composer
scripts, add a scripts to composer.json
:
{ "name": "foo/bar", "require": { "php": "^7.4", }, "require-dev": { "visual-craft/php-cs-fixer-config": "*" + }, + "scripts": { + "cs-check": "vendor/bin/php-cs-fixer fix --dry-run --diff -v --ansi", + "cs-fix": "vendor/bin/php-cs-fixer fix --diff -v --ansi" } }
Run
$ composer cs-fix
to automatically fix coding standard violations.
Run
$ composer cs-check
to automatically show coding standard violations.
Credits
Developed by Visual Craft, inspired by ergebnis/php-cs-fixer-config.
License
This project is under the MIT license.