PHPCode Sniffer + Sublime on windows

Things you need for:

  1. cmder
  2. composer
  3. Sublime Text 2/3

We are going to install using composer, because it will automatically install related packages. So no need to do too many manual stuffs.

Step 1: Open “cmder” and run following command

composer global require "squizlabs/php_codesniffer=*"

This will install php code sniffer into your system.

Step 2: Now run following command into “cmder”.

composer create-project wp-coding-standards/wpcs --no-dev

This will install and register WordPeress coding standards into code sniffer.

 

Now we will integrate the code sniffer into sublime text editor. You will need package installer for that. You can install that from here

Step 3: Open Sublime Text editor and press ctrl+shft+p. You will get the textbox into editor. Type “install package” into that and press enter and wait for a while, don’t change the window.

Step 4: After a while you will again get a textbox. Type “phpcs” and you will get the result and click on “phpcs” and wait. This will install code sniffer package for sublime.

Step 5: Go to “Preferences->Package Settings->PHP Code Sniffer->Settings-Default“.

Step 6: Add “phpcs_executable_path” as shown below.

"phpcs_executable_path": "C:\\Users\\YOUR_USERNAME\\wpcs\\vendor\\bin\\phpcs.bat",

Step 7: Save the file and restart sublime.

That’s it….!!!!!!! Code sniffer is integrate with sublime.

To check if it’s working or not, open any PHP file and “right click->PHP Code Sniffer->Switch coding standards” and chose any coding standard which you want.

After that again “right click->PHP Code Sniffer->Sniff this file“. You will get some error according to your chosed coding standard.

So that’s all for now. If you have any question, then write down into comments. I will try to answer those questions.

2 Comments

Thanks for this tutorial Bhargav. Really helpful.

We are selecting “WordPress” as default standard at the moment.