realodix/cs-config

This package is abandoned and no longer maintained. The author suggests using the realodix/relax package instead.

Shared php-cs-fixer rules & finders preset

v1.1.1 2022-07-30 21:03 UTC

This package is auto-updated.

Last update: 2022-08-12 04:31:49 UTC


README

This package is abandoned, you should avoid using it. Use realodix/relax instead.

Realodix CS Config

PHPVersion Build Status

This package is built on top of PHP CS Fixer and makes it simple to to sharing identical PHP CS Fixer rules across all of your projects without copy-and-pasting configuration files.

Installation

You can install this package by using composer:

composer require --dev realodix/cs-config
PHP Version
>= 7.1 1.0.x
>= 7.4 1.1.x

Configuration

In your PHP CS Fixer configuration file, use the following contents:

<?php

use Realodix\CsConfig\Config;
use Realodix\CsConfig\Finder;
use Realodix\CsConfig\Rules\Realodix;

return Config::create(new Realodix);

Finder Presets

Rulesets

💡 Namespace Realodix\CsConfig\Rules\

Custom Fixers

💡 It's already registered, so you no longer need to register it via registerCustomFixers().

Advanced Configuration

In case you only need some tweaks for specific projects, which won't deserve an own preset - you can add additional rules or override them.

<?php

use Realodix\CsConfig\Config;
use Realodix\CsConfig\Finder;
use Realodix\CsConfig\Rules\Realodix;

$localRules = [
    // Adding a rule
    'array_syntax' => true,
    // Adding a rule or override predefined rules
    'binary_operator_spaces' => [
        'operators' => ['=>' => 'align_single_space_minimal']
    ],
    // Override predefined rules
    'ternary_operator_spaces' => false,
    // Adding custom rules
    'CustomFixer/rule_1' => true,
    'CustomFixer/rule_2' => true,
];

return Config::create(new Realodix($localRules))
    ->registerCustomFixers(new PhpCsFixerCustomFixers\CustomFixer());

Extending

You can easily create your own presets by extending the AbstractRules class.

<?php

use Realodix\CsConfig\Rules\AbstractRules;

final class MyRules extends AbstractRules
{
    // public string $name = 'Personal CS';

    protected function rules(): array
    {
        //
    }
}

And use it!

<?php

use Realodix\CsConfig\Config;
use Realodix\CsConfig\Finder;
use YourVendorName\YourPackageName\MyRules;

$finder = Finder::base(__DIR__);

return Config::create(new MyRules)
    ->setFinder($finder);

Troubleshooting

For general help and support join our GitHub Discussions.

Please report bugs to the GitHub Issue Tracker.

License

This package is licensed under the MIT License.