Skip to content

Visual-Craft/php-cs-fixer-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

php-cs-fixer-config

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:

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.