visual-craft / php-cs-fixer-config
Configuration for friendsofphp/php-cs-fixer
Installs: 17 283
Dependents: 2
Suggesters: 0
Security: 0
Stars: 1
Watchers: 3
Forks: 1
Open Issues: 0
pkg:composer/visual-craft/php-cs-fixer-config
Requires
- php: ^7.4 || ^8.0
- friendsofphp/php-cs-fixer: ^3.87
- kubawerlos/php-cs-fixer-custom-fixers: ^3.34
- pedrotroller/php-cs-custom-fixer: ^2.34
Requires (Dev)
- ergebnis/composer-normalize: ^2.48
- vimeo/psalm: ^6.13
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\Php74VisualCraft\PhpCsFixerConfig\RuleSet\Php80VisualCraft\PhpCsFixerConfig\RuleSet\Php81VisualCraft\PhpCsFixerConfig\RuleSet\Php82VisualCraft\PhpCsFixerConfig\RuleSet\Php83VisualCraft\PhpCsFixerConfig\RuleSet\Php84
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\Php84()); $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\Php84());
+$config = PhpCsFixerConfig\Factory::fromRuleSet(new PhpCsFixerConfig\RuleSet\Php84(), [
+ '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.