You can save yourself quite some time by running a simple command to automatically format your PHP/Laravel code to follow the PSR-1 and PSR-2 standards. Let me show you how you can set it all up to work with Sublime Text 3 on OS X.
You must have at least
PHP 5.3.6 on your system. Check with
Run the following commands to download php-cs-fixer:
wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer
curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer
If you prefer a different download method such as composer or homebrew, check out these instructions.
Now that you’ve downloaded php-cs-fixer, make it executable:
sudo chmod a+x php-cs-fixer
Move it to a global location:
sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
Check that it works by running:
If everything is fine, you should see the version and usage information.
- Open Sublime Text
- Got to Tools > Build System > New Build System…
- Enter the following command and save:
"shell_cmd": "php-cs-fixer fix $file --level=psr2"
That’s it. When you run this command, php-cs-fixer will apply psr-2 standards to the current file you have open.
Run the command by pressing
Command + B.