Skip to content

Automatically fix PHP coding standards configuration for projects

License

Notifications You must be signed in to change notification settings

focela/php-cs-fixer

Repository files navigation

PHP CS Fixer Config

This repository provides a base configuration for friendsofphp/php-cs-fixer, which we use to verify and enforce a single coding standard for PHP code.

Installation

composer require --dev focela/php-cs-fixer

Quick Start

Now that the package is installed, create a configuration file called .php_cs, .php_cs.php or .php-cs-fixer.php at the root of your project with the following contents:

<?php

// Create a new CS Fixer Finder instance
$finder = PhpCsFixer\Finder::create()->in(__DIR__);

return Focela\PhpCsFixer\Config::create()
    ->setFinder($finder);

Ignoring files and/or directories

  • There will be certain situations where you might want to ignore certain files or directories to not be linted.
  • Luckily, this is quite easy to achieve and all you need to do is to perform some calls on the CS Fixer Finder instance :)
  • Here's a simple example where we ignore both files and directories:
<?php

// Directories to not scan
$excludeDirs = [
    'vendor/',
];

// Files to not scan
$excludeFiles = [
    'config/app.php',
];

// Create a new CS Fixer Finder instance
$finder = PhpCsFixer\Finder::create()
    ->in(__DIR__)
    ->exclude($excludeDirs)
    ->ignoreDotFiles(true)
    ->ignoreVCS(true)
    ->filter(function (\SplFileInfo $file) use ($excludeFiles) {
        return ! in_array($file->getRelativePathName(), $excludeFiles);
    });

return Focela\PhpCsFixer\Config::create()->setFinder($finder);

Contributing

We encourage and support an active, healthy community of contributors — including you! Details are in the contribution guide and the code of conduct. The php-cs-fixer maintainers keep an eye on issues and pull requests, but you can also report any negative conduct to [email protected]. That email list is a private, safe space; even the php-cs-fixer maintainers don't have access, so don't hesitate to hold us to a high standard.


Released under the MIT License.