phpsymfonycoding-stylepsr-2

php-cs-fixer: need more information on using fix --level option


Okay, I know php-cs-fixer allows following levels of fixes for coding standards:

php php-cs-fixer.phar fix /path/to/project --level=psr0
php php-cs-fixer.phar fix /path/to/project --level=psr1
php php-cs-fixer.phar fix /path/to/project --level=psr2
php php-cs-fixer.phar fix /path/to/project --level=symfony 

I know that psr0, psr1, psr2 levels maintain specified coding standards.

But I want to know what --level=symfony offers and how does that coding standard differ from psr2.

Also if we don't the provide the --level option at all. Does is assume --level=psr2 by default?


Solution

  • Here's a good blog post on using php-cs-fixer and here it implies that by default it uses psr2 fixers if the --level option is not provided.

    But, if we pass --level=symfony explicitly it runs some “additional” checks, which are targeted at Symfony and go above-and-beyond PSR2

    By default, it runs “all PSR-2 fixers and some additional ones.” You can toggle the level you want to run with the --level flag, which I’ll be setting to psr2 so that the “additional” checks, which are targeted at Symfony and go above-and-beyond PSR2, don’t throw me off. (It runs the entire stack by default, which is called level “symfony” and includes things like “Align equals signs in subsequent lines”).

    Also the php-cs-fixer README on github provides some information about the filters that are run in PSR-0, PSR-1, PSR-2 and symfony.