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:
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:
Move it to a global location:
Check that it works by running:
If everything is fine, you should see the version and usage information.
Configure a Build Command in Sublime Text 3
- Open Sublime Text
- Got to Tools > Build System > New Build System…
- Enter the following command and save:
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.