madewithlove/php-cs-fixer-config

Prebuilt PHP CS Fixer configuration for Madewithlove projects

3.1.0 2022-12-14 12:17 UTC

This package is auto-updated.

Last update: 2024-09-16 11:57:17 UTC


README


madewithlove

madewithlove PHP-CS-Fixer configuration

The default PHP-CS-Fixer configuration for madewithlove projects.

ci pull requests contributors

Built with ❤️︎ and ☕ by heroes at madewithlove.

Installation

$ composer require madewithlove/php-cs-fixer-config --dev

Usage

Basic usage

.php-cs-fixer.php

<?php

require 'vendor/autoload.php';

return Madewithlove\PhpCsFixer\Config::fromFolders(['src']);

To exclude a subfolder:

<?php

require 'vendor/autoload.php';

return Madewithlove\PhpCsFixer\Config::fromFolders(['src'], null, ['ignoreThisDir']);

This will skip src/ignoreThisDir or src/foo/bar/ignoreThisDir. (The folder has to be relative to the ones in the first argument.)

You can also override rules per-project without overriding the core rules like this:

.php-cs-fixer.php

<?php

require 'vendor/autoload.php';

return Madewithlove\PhpCsFixer\Config::fromFolders(['src'])->mergeRules([
   'php_unit_strict' => false,
]);

Usage within a Laravel project

You can also preconfigure the configuration for a Laravel project by calling a special factory method:

.php-cs-fixer.php

<?php

require 'vendor/autoload.php';

return Madewithlove\PhpCsFixer\Config::forLaravel();

If need be, you can also append folders to fix in addition to Laravel's:

.php-cs-fixer.php

<?php

require 'vendor/autoload.php';

return Madewithlove\PhpCsFixer\Config::forLaravel(['some_other_folder']);

Targeting a specific PHP version

By default, the configuration will check the version of PHP you run the tool with, and proceed to enable/disable fixers depending on it.

You can override the target PHP version by passing it either as constructor argument, or as second argument to fromFolders:

.php-cs-fixer.php

<?php

require 'vendor/autoload.php';

return Madewithlove\PhpCsFixer\Config::fromFolders(['src'], '7.4');

// or

return Madewithlove\PhpCsFixer\Config::forLaravel([], '7.4');