Provides a configuration factory and multiple rule sets for friendsofphp/php-cs-fixer
.
Run
$ composer require --dev visual-craft/php-cs-fixer-config
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;
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;
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.
Developed by Visual Craft, inspired by ergebnis/php-cs-fixer-config.
This project is under the MIT license.