Schedule a Free Consultation
Install Php Code Sniffer on Windows & PHPStorm

Install Php Code Sniffer on Windows & PHPStorm

Read Article

If you are concerned about delivering high-quality code, compliant with WordPress coding standards, you’d better use an automated tool for these checks.

PHP Code Sniffer together with PHPStorm editor is a great and powerful combination as you get all these code checks in real time, as you type your code.

There are many great tutorials on how to install PHP Code Sniffer with PHPStorm on Mac, but we did not find any article explaining how to install and configure these tools on Windows.

So here’s a small contribution for those who need to check their code on Windows:

  1. Using Composer
    1. Installing PHP Code Sniffer
      Install composer: https://getcomposer.org/download/
      Follow instruction from: https://github.com/squizlabs/PHP_CodeSniffer#composer
    2. Update
      Open cmd
      Run this command: composer global update “squizlabs/php_codesniffer”
  2. Using PEAR
    1. Install PHP. Suggested are bundle: XAMPP OR WAMP
      1. Restart computer
      2. XAMPP ship with PEAR and PHP_CodeSniffer you can skip steps 2-
      3. To check if PHP_CodeSniffer is installer run this command in CMD: phpcs -i
    2. Add System Environment variable: https://www.screencast.com/t/1zs1WY31l with link to PHP.exe from BIN folder
    3. How to install PEAR(if needed)
      1. Download from: http://pear.php.net/go-pear.phar
      2. Copy PEAR to php location
      3. Open CMD to this location. Can be done two ways
        1. RUN -> write cmd -> CD into your php server folder
        2. Open Explorer -> go to PHP location -> SHIFT + RIGHT CLICK there and open SHELL
      4. RUN command php go-pear.phar
        1. Check folder settings to be OK
        2. Follow on screen details and complete installation
    4. Install PHP_CodeSniffer
      1. Run command from cmd(see step 3-C-i and 3-C-ii) pear install PHP_CodeSniffer from PHP -> PEAR folder
      2. Download WORDPRESS STANDARDS from https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards/archive/master.zip
      3. Unpack the archive folders: https://www.screencast.com/t/jgucqIDo to ~phpPEARphpCodeSniffersrcStandards where ~ means path to PHP
    5. For Updates you need to download the WORDPRESS STANDARDS from the link above and copy them to CodeSniffer location.
  3. PHPStorm settings – is suggested to work on “default settings” dialog (from File)
    1. Make PHPStorm exe run as administrator. From compatibility properties on exe file.
    2. Make sure you have a valid PHP interpretor setup in PHPStorm: https://www.screencast.com/t/y6F79xUg60
    3. Adding PHPCodeSniffer to PHPStorm CodeSniffer
      1. Setup Composer path in PHPStorm: https://www.screencast.com/t/52VzidnWb
      2. Go to Langauages & Frameworks -> PHP -> Code Sniffer https://www.screencast.com/t/APUubpoN
      3. Using PEAR: Setup point 3 from screenshot by adding: ~phpphpcs.bat
        Using Composer: Set point 3 from screenshot by adding: path_to_composer_globalvendorsquizlabsphp_codesnifferbinphpcs.bat
      4. Click Validate. If no error you are good!
      5. Change PHP inspector to: https://www.screencast.com/t/ySgOPmaVxQ
        1. Make sure PHP Code Sniffer validator is checked

Reference:
https://github.com/squizlabs/PHP_CodeSniffer
https://w3guy.com/setup-php-code-sniffer-phpstorm-windows/
https://kellenmace.com/set-up-php-codesniffer-in-phpstorm-with-wordpress-coding-standards/

Navigate to

Check some other articles we wrote

Effective business directory layout saves time
Choosing a business directory layout makes a difference. For a business site that wants to attract visitors to its content, deciding on how to present the data is as important as it is difficult. In this article, we present a novel and interesting method of showing categorical information. When presenting data organized in categories, the […]
Opening Isotope panel in modal view
We matched Isotope’s innate ability to manage content with the need to display more details in a modal view. The popular Isotope framework for displaying content offers novel ways of arranging elements on a page. Specifically, in this post, we explain how we managed to display the content of table cell under the current table […]
How to Choose the Best WordPress Maintenance Agency for Your Business [Complete Step by Step Guide]
WordPress started in 2003 as a blogging platform and made a phenomenal transition to an excellent CMS that now powers 43% of all websites, according to the latest statistics provided by W3Techs. Check here what you can build with WordPress. But like all software, things occasionally go wrong and need fixing. This and a couple […]