Skip to content

Instantly share code, notes, and snippets.

@sudiptpa
Created October 12, 2015 01:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sudiptpa/9e5bc73831f455dd7793 to your computer and use it in GitHub Desktop.
Save sudiptpa/9e5bc73831f455dd7793 to your computer and use it in GitHub Desktop.
PSR-2 Build System using Sublime Text

PSR-2 Build System using Sublime Text

Installation

Open a new terminal and install Composer:

curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer

Once that has finished installing and moved, install the PHP-CS-Fixer Composer package globally:

composer global require fabpot/php-cs-fixer

Ensure you can run PHP-CS-Fixer globally by running php-cs-fixer -v in a new terminal window.

Then open Sublime Text and go to Tools > Build System > New Build System... - this will create a new untitled.sublime-build file, in which you can drop this snippet in:

{
    "path": "$HOME/.composer/vendor/bin",
    "shell_cmd": "php-cs-fixer fix '$file' --level=psr2"
}

Hit 'Save', rename this file as php.sublime-build and save it in the same directory. As @jegra suggested, you don't need the first line if you're on Windows.

Usage

Now every time you use the php build system, your code will automatically be reformatted to conform with PSR-2. You can run a build system by:

  • Opening the Command Palette and selecting Build with: php. All your build commands are listed in there.
  • Going to Tools > Build System > php (then running subsequent builds with Tools > Build).
  • Hitting Cmd+B (or Ctrl+B on Windows I think).

Finally, you can check Tools > Save All on Build to also save whenever you build. Easy!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment