Ensuring All Stray PHP Files Are Run Through ECS

Easy Coding Style is a really nice code-style checking tool. It combines the best of both PHP-CS-Fixer and PHP Code Sniffer, it's easy to use and has a declarative config with all kinds of useful options. One of the fundamental options is $ecsConfig->paths([]), this is simply an array of all the files and directories to check.

I was slightly disappointed when I discovered that wildcards aren't supported because I wanted to include those PHP files which accumulate in the root of the project. For example rector.php or ecs.php. I could just list them directly but then I would have to remember to update it every time a file was added or removed.

A better option was to dynamically generate the list. This was easily achieved with a combination of the glob function and the spread operator:

<?php

return function (ECSConfig $ecsConfig): void {
    $ecsConfig->paths([
        __DIR__ . '/app',
        __DIR__ . '/config',
        __DIR__ . '/tests',
        ...glob(__DIR__ . '/*.php'),
    ]);
});

Popular Reads

Subscribe

Keep up to date

Please provide your email address
Please provide your name
Please provide your name
No thanks