PHP Coding Standards Fixer: Let’s Put It To Work!

Nice i just embedded php-cs-fixer for my project. I git clone it to a ../php-cs-fixer dedicated git folder so i can update and have it permanently symlinked as /usr/bin/php-cs-fixer. Then I created my .php_cs like in the instructions on the github readme page. Then i ran into problems and comparing to what the –config=sf21 does I wrote my own .php_cs:

<?php
use Symfony\CS\FixerInterface;
 
$finder = Symfony\CS\Finder\DefaultFinder::create()
    ->exclude(
        array(
                'Vendor/DemoBundle/Resources/public/js',
                'Vendor/DemoBundle/Resources/public/img',
                'Vendor/DemoBundle/Resources/public/css',
        )
    )
    ->in(__DIR__.'/src')
;
 
return Symfony\CS\Config\Config::create()
    ->finder($finder)
    ->fixers(FixerInterface::ALL_LEVEL);
;

Then you just run it like a boss:

~ php-cs-fixer fix .

Performance review: Make sure you add that src limit so that it will not take forever to scan your vendor folder.
In addition I noticed that the main changes on my code were the removal of use statements, the addition of space lines and removal of wrong ordered things like `public static` from `static public`. Other than that I guess I bet it is going to get more fixers as they come available from contributions.

Now to continue with the project by His grace.

Leave a Reply

Your email address will not be published. Required fields are marked *