Code analysers as PHP Code Sniffer, and coding standards as WordPress Coding Standards, allow to create a modern, easily maintainable code, and avoid multiple errors even during writing of the code. They are indispensable for team development of a project. These tools are embedded into PhpStorm – modern powerful Integrated Development Environment (IDE).
At the same, many novice developers have troubles installing PHP Code Sniffer analyser and WordPress Coding Standards in PhpStorm on Windows. Information is dispersed by many articles in the Internet.
Below, we will join information on it in one place and show installation sequence step by step.
Installing PHP
Open the page http://windows.php.net/download/ and select 32 or 64-bit file depending on your system architecture.
There are also TS (Thread Safe) and NTS (Non Thread Safe) variants. TS differs in that it allow PHP to work in several threads. For simple applications and web site development NTS is enough.
Unpack zip-archive, for instance, to c:\php
.
Rename file c:\php\php.ini-development
to c:\php\php.ini
.
Found the line ;On windows:
and uncomment after it
extension_dir = "ext"
To works with WordPress, we need several extensions.
Found the section ; Windows Extensions
and comment lines
extension=php_mbstring.dll
extension=php_mysqli.dll
Found line ;date.timezone =
, uncomment it and setup your timezone, for instance:
date.timezone = 'Europe/Riga'
Finally, add lines for Xdebug debugger to the end of the file.
[xdebug]
zend_extension=c:/php/ext/php_xdebug-2.7.2-7.3-vc15-nts-x86_64.dll
xdebug.remote_autostart=on
xdebug.remote_enable=on
xdebug.remote_handler="dbgp"
xdebug.remote_host="localhost"
xdebug.remote_port=9001
xdebug.remote_mode=req
xdebug.idekey="ваш_пароль"
Debugger by its own should be downloaded as dll-file from here: https://xdebug.org/download.php and put into c:\php\ext
. At downloading you should select the same PHP version and architecture, which was selected during PHP install.
Installing Composer
To continue, we need Composer.
Download the file https://getcomposer.org/Composer-Setup.exe into c:\php
.
Run Composer-Setup.exe
and perform default setup.
For activation of Composer path it is needed to restart cmd window.
Composer added, and now you can use it to install other packages.
Installing Git
Installation of Git on Windows has no problems. Product can be downloaded here здесь. Also, Git is included into some local web servers, like Laragon.
Installing WordPress Coding Standards
Run `cmd.exe` and enter commands
c:
cd \
git clone https://github.com/WordPress/WordPress-Coding-Standards.git
cd WordPress-Coding-Standards
composer install
Open in PhpStorm project settings window (Ctrl+Alt+S
) and select Languages&Frameworks → PHP.
Select PHP language level (7.3).
Click on ellipsis to the right from CLI Interpreter.
In the CLI Interpreters window select file PHP executable (C:\php\php.exe
) and Debugger extension (C:\php\ext\php_xdebug-2.5.5-7.1-vc14-x86_64.dll
). On the picture below there are paths for Laragon. Use your own.
Click OK.
In the same window select Languages&Frameworks → PHP → Quality Tools → Code Sniffer.
Specify path to it C:\WordPress-Coding-Standards\vendor\bin\phpcs.bat
.
Click Validate, make sure that everything is OK (please see the message OK, PHP_CodeSniffer version 3.4.2 (stable) by Squiz).
Click OK.
In the same settings window select Editor → Inspections → PHP → Quality Tools → PHP Code Sniffer validation and required Coding standard. If in the list of standards you do not see WordPress, click on the reload button to the right (circular arrows).
We recommend to use WordPress — most strict coding standard, which includes WordPress-Core, WordPress-Docs, WordPress-Extra. More details are here: https://github.com/WordPress-Coding-Standards/WordPress-Coding-Standards
Process of installation is over, and you can create professional code on WordPress.