This plugin adds PHP CodeSniffer, PHP Code Beautifier and Fixer, PHP Coding Standards Fixer, the PHP Linter, PHP Mess Detector, Scheck support to Sublime Text.
For more information about this plugin such as features, installation requirements etc, please see: http://benmatselby.github.io/sublime-phpcs
- Download and install composer
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- Make sure to add
~/.composer/vendor/bin
directory to your PATH
- Using Package Control:
Preferences > Package Control > Install Package > Phpcs
- Or Manually:
cd ~/Library/Application\ Support/Sublime\ Text\ 3/Packages/
git clone git://github.com/benmatselby/sublime-phpcs.git Phpcs
- Install both phpcs and phpcbf with:
sudo composer global require "squizlabs/php_codesniffer=*"
- Install phpmd:
sudo composer global require "phpmd/phpmd=*"
- Finally install php-cs-fixer
sudo composer global require "fabpot/php-cs-fixer=*"
- Take note of the path for the newly installed apps:
which phpcs
which phpcbf
which phpmd
which php-cs-fixer
(This path is usually /Users/NAME/.composer/vendor/bin/ on a Mac)
This file is under Preferences > Package Settings > PHP Code Sniffer > Settings User
{
"phpcs_php_path": "/path/to/bin/phpcbf",
"phpcs_executable_path": "/path/to/bin/phpcs",
"phpmd_executable_path": "/path/to/bin/phpmd",
"php_cs_fixer_executable_path": "/path/to/bin/php-cs-fixer",
"phpcs_show_errors_on_save": false,
"phpcs_outline_for_errors": false,
"php_cs_fixer_on_save": false
}
This file is under Preferences > Key Bindings - User
[
{
"keys": ["super+k", "super+f"],
"command": "phpcs_fix_this_file",
"args": { "tool": "Fixer" }
}
]
You now can press "super+k", "super+f" to format your code to PSR-2