Skip to content

Instantly share code, notes, and snippets.

@vukanac vukanac/README.md forked from mikefrancis/README.md
Created Sep 19, 2016

Embed
What would you like to do?
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.

If you can't, make sure the composer bin directory is in your PATH:

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

Thanks to @Migweld for the above.

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",
    "show_panel_on_build": false
}

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
You can’t perform that action at this time.