visual-craft/php-cs-fixer-config

Configuration for friendsofphp/php-cs-fixer

v0.4.0 2023-12-21 10:40 UTC

This package is auto-updated.

Last update: 2024-04-21 11:16:33 UTC


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:

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.