Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save madebymode-devs/bc6655712eeba1a1506a to your computer and use it in GitHub Desktop.
Save madebymode-devs/bc6655712eeba1a1506a to your computer and use it in GitHub Desktop.

Configuring phpfmt for Sublime Text and PSR Coding Standards

Installation

  1. Use Homebrew to install PHP 5.5:
    • brew install php55
  2. Install the plugin through Package Manager:
    • In Sublime Text press ctrl+shift+P
    • Choose Package Control: Install Package
    • Choose phpfmt
  3. Update your preferences to adhere to PSR standards:
    • Preferences > Package Settings > phpfmt > Settings - User
    • Paste the code below and save

Settings

{
    "psr1":false,
    "psr2":true,
    "php_bin":"/usr/local/bin/php",
    "indent_with_space":true,
    "format_on_save":true,
    "disable_auto_align":true
}

This will auto-format your code to PSR standards every time you save a PHP file.

Notes

  • If needed, run which php to update the location of your PHP binary.
  • psr1 forces text after PHP open tags to a new line, meaning you can't neatly add echo statements into your markup. Planning to create an issue and pull request. In the meantime, just set to false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment