I got the tutorials originally from http://code.tutsplus.com/tutorials/psr-duh--net-31061. Install into your sublime text editor via Package Control the Phpcs plugin(https://github.com/benmatselby/sublime-phpcs).
Then these are the packages which should be installed in your machine:
phpcs
"squizlabs/php_codesniffer":"*"phpcbf
"squizlabs/php_codesniffer":"*"php-cs-fixer
"fabpot/php-cs-fixer":"*"phpmd
"phpmd/phpmd":"*"
First try first the commands if it is already installed by typing the command name, e.g., $ phpcs
If already installed, type: which
then the command name, e.g. $ which phpcs
and it will give you the location of the
binary which is the required settings of Phpcs sublime plugin.
Each package has .phar
which should be downloaded and made as executable.
Package | Download link |
---|---|
phpcs |
https://squizlabs.github.io/PHP_CodeSniffer/phpcs.phar |
phpcbf |
https://squizlabs.github.io/PHP_CodeSniffer/phpcbf.phar |
php-cs-fixer |
http://get.sensiolabs.org/php-cs-fixer.phar |
phpmd |
http://static.phpmd.org/php/latest/phpmd.phar |
- Download the
.phar
file of each package and install.
```
$ wget <download_link> -O <package>
$ sudo chmod a+x <package>
$ sudo mv <package> /usr/local/bin/<package>
```
composer global require squizlabs/php_codesniffer
composer global require friendsofphp/php-cs-fixer
Include the packages in global composer.json
and run the $ composer global update
.
The repository packages are mentioned above.
Location of composer.json
: ~/.composer/composer.json
Then copy the paths of the package into the Phpcs plugin settings.
Include the packages in global composer.json
and run the $ composer global update
.
The repository packages are mentioned above.
Location of composer.json
: C:/Users/<user>/AppData/Roaming/Composer/composer.json
Then copy the paths of the .bat
packages into the Phpcs plugin settings.
{
"phpcs_additional_args": {
"--standard": "PSR2",
"-n": ""
},
"phpcs_executable_path": "/usr/bin/phpcs",
"phpmd_executable_path": "/usr/local/bin/phpmd",
"phpcbf_executable_path": "/usr/bin/phpcbf",
"php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer"
}
Install this to get the necessary .bat or executable files, https://github.com/squizlabs/PHP_CodeSniffer
Then set the path in user settings of the package
That's all you need to make phpcs work.