-
Install the package using Package Control - PhpCs(sublime-phpcs)
-
Download the phar files needed for the functioning of the plugin:
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar
curl -OL https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar
curl -OL http://static.phpmd.org/php/latest/phpmd.phar
curl -OL http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar
-
Add executable permission to the phar files(applicable only in Mac and Linux): chmod +x php-cs-fixer-v2.phar phpcs.phar phpcbf.phar phpmd.phar
-
Configuring the plugin. In the Sublime text menu:
Preferences > Package Settings > PHP Code Sniffer
, you can find the Settings - Default
and Settings - User
files. The former is the template file, you can start by copying its content to Settings - User
file. Once this is done, we now have to set paths for some executables to get the plugin working.
For basic functionality, I suggest that the following entries are updated:
-
phpcs_execute_on_save
- By default the value isfalse
, change that totrue
-
In the following entries, specify the absolute path to the phar files you have download previously:
"phpcs_executable_path"
"php_cs_fixer_executable_path"
"phpcbf_executable_path"
"phpmd_executable_path"
- For the following entries, you need to specify the absolute path to the
php
executable. Usually needed only in Windows, but can be used in Linux/Mac if you're using a non-standard install, which may not be present in the PATH environment variable:
"phpcs_php_prefix_path"
"phpcs_php_path"
"phpcs_executable_path": "/Users/username/phpcs.phar"
"php_cs_fixer_executable_path": "/Users/username/php-cs-fixer-v2.phar"
"phpcbf_executable_path": "/Users/username/phpcbf.phar"
"phpmd_executable_path": "/Users/username/phpmd.phar"
"phpcs_php_prefix_path" : "/Applications/MAMP/bin/php/php7.1.1/bin/php"
"phpcs_php_path" : "/Applications/MAMP/bin/php/php7.1.1/bin/php"