I want to learn to code PHP to standard. I found this article and (on its advice) installed phpcs in sublime text 2. If I go to tools -->phpcode sniffer -->sniff this file it will find syntax errors but not coding standard deviations. (Here is the code I am trying to sniff, which I think has many deviations from standard https://codereview.stackexchange.com/questions/57045/simple-wrapper-for-an-api).
The docs say to configure phpcs to use a coding standard via phpcs_additional_args
. If I go to sublimetext2->preferences->package settings->phpcode sniffer->settings user I see the following code:
"phpcs_additional_args": {
"--standard": "PSR2",
"-n": ""
},
Here is my full config file.
Do I have the workflow right? If so, why isn't it finding my mistakes? How do I use phpcs to teach myself coding standards? Even knowing that I am doing the correct steps but the plugin is not outputting the coding standard marks would be helpful.
Based on your configuration file, there are some things you must fix:
Following instructions are for linux (ubuntu), or mac
Install php code sniffer
pear install PHP_CodeSniffer
reload your bash or zsh and then execute command, if you don't know how to do this, just restart your terminal app
which phpcs
copy the output and paste to "phpcs_executable_path":
at phpcs config
currently, you're pointing "phpcs_executable_path":
to php, not phpcs, so thats why its doesn't work
Install php mess detector
pear channel-discover pear.phpmd.org
pear channel-discover pear.pdepend.org
pear install pdepend/PHP_Depend
pear install --alldeps phpmd/PHP_PMD
do like phpcs above
reload enviroment and execute which phpmd
, then fill "phpmd_executable_path": ""
at phpcs config
install php-cs-fixer
sudo wget http://get.sensiolabs.org/php-cs-fixer.phar -O /usr/local/bin/php-cs-fixer
sudo chmod a+x /usr/local/bin/php-cs-fixer
change "php_cs_fixer_executable_path": ""
to "php_cs_fixer_executable_path": "/usr/local/bin/php-cs-fixer"
install scheck
cd /opt/
git clone --depth=1 https://github.com/facebook/pfff.git
cd pfff/
./configure
make depend
make
make opt
change "scheck_executable_path"
to "scheck_executable_path": "/opt/pfff/scheck"
Note: you may use sudo pear ...
instead pear ...
I use it with phpstorm because it near enough works out of the box, however I think this might be were you find your answer: https://github.com/benmatselby/sublime-phpcs
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With