Skip to content

PHP PSR Auto Formatting Tool

Reading Time: < 1 minute

PSR format is one of the code formatting standard of PHP. Its very tough to format each and every line in big projects. To Resolve this PSR auto formatting tool is available as opensource kit called – PHP-CS-Fixer. You can simply use it from command line and change your code formatting within seconds.

1. Install the PHP-CS-Fixer via Composer

Installig PHP-CS-Fixer via composer is very easy task to go. You can run composer with this command. It will download and install the PHP-CS-Fixer within minutes.

$ composer global require fabpot/php-cs-fixer @stable

Set Path

Setting path is important to run PHP-CS-Fixer.

export PATH="$PATH:$HOME/.composer/vendor/bin"

Test Drive

After Installed and set path its time to run PHP-CS-Fixer. But before do it on real time make sure it will run and properly works. Use this command to check the tool without changing anything.

$ php-cs-fixer fix ./ --level=psr2 --dry-run

Real Run

Now this is time to run PHP-CS-Fixer for realtime purpose. You can use a single file or a folder in a single command to get format done within seconds.

$ php-cs-fixer fix ./ --level=psr2
See also  CRM vs ERP

Leave a Reply