werxe/php-cs-fixer-config

PHP CS Fixer configuration for Werxe projects

v2.0.0 2021-05-05 21:44 UTC

This package is auto-updated.

Last update: 2024-11-06 05:40:18 UTC


README

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 written on Werxe.

Installation

Run the following:

composer require --dev werxe/php-cs-fixer-config

Usage

Now that the package is installed, create a configuration file called .php_cs or .php_cs.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 (new Werxe\PhpCsFixer\Config())
    ->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 (new Werxe\PhpCsFixer\Config())
    ->setFinder($finder)
;

Enforce coding standards for PHPUnit tests

If you would like to also enable coding standards on your tests, you can call the withPHPUnitRules() method on the Config class, like so:

<?php

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

return (new Werxe\PhpCsFixer\Config())
    ->setFinder($finder)
    ->withPHPUnitRules()
;

Contributing

Thank you for your interest in PHP CS Fixer Config. Here are some of the many ways to contribute.

Security

If you discover any security related issues, please email security@werxe.com instead of using the issue tracker.

License

PHP CS Fixer Config is licenced under the MIT License (MIT). Please see the license file for more information.