Skip to content

gomzyakov/php-cs-fixer-config

Repository files navigation

Code-style configuration for php-cs-fixer

packagist downloads_count license codecov

This package allows sharing identical php-cs-fixer formatting rules across all of your projects without copy-and-pasting configuration files.

Quickstart

Step 1 of 3

Install friendsofphp/php-cs-fixer & this package via Composer:

composer require --dev friendsofphp/php-cs-fixer gomzyakov/php-cs-fixer-config

Step 2 of 3

Then create file .php-cs-fixer.dist.php at the root of your project with following contents:

<?php

use Gomzyakov\CS\Finder;
use Gomzyakov\CS\Config;

// Routes for analysis with `php-cs-fixer`
$routes = ['./src', './tests'];

return Config::createWithFinder(Finder::createWithRoutes($routes));

Change the value of $routes depending on where your project's source code is.

Step 3 of 3

And that's it! You can now find code style violations with following command:

./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php --dry-run

And then completely fix them all with:

./vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php

Configuration

You must pass a set of routes to the Finder::createWithRoutes() call. For example, for Laravel projects, this would be:

Finder::createWithRoutes(['./app', './config', './database', './resources', './routes', './tests'])

Also, you can pass a custom set of rules to the Config::createWithFinder() call:

Config::createWithFinder($finder, [
    '@PHP81Migration'   => true,
    'array_indentation' => false
])

Laravel Pint

The following describes the use of styles in conjunction with friendsofphp/php-cs-fixer. Also you can use these style settings for Laravel Pint.

Support

If you find any package errors, please, make an issue in current repository.

License

This is open-sourced software licensed under the MIT License.

Special thanks