Code sur écran d'ordinateur

PHP style code: How to keep its code clean with PHP Coding Standards Fix

A really useful tool to keep your code clean is PHP Coding Standards Fixer.

It allows us to follow the PHP standards defined in PSR-1, PSR-2, etc. It is also possible to configure it to follow the style of your team with a documentation.

The recommended way to install it is outside your code, but if you use Symfony, you can install it directly as a dependency of your project.

compose requires --dev friendsofphp/php-cs-fixer

Once this is done, it can be launched in the following way

php vendor/friendsofphp/php-cs-fixer/php-cs-fixer fix src

During the first execution, the configuration is created

php-cs-fixer

And the first corrections take place. So your code will follow the rules of PHP, PSR without you needing to be too careful during PRs.

Don’t forget to commit the .php_cs.dist file!

Leave a comment