Scanning code locally with PHP_CodeSniffer (PHPCS) provides useful feedback on code quality based on a defined set of coding standards.
Instructions for optional methods of installing PHPCS for WordPress VIP:
- Install PHPCS globally so that PHPCS is available from anywhere on the local machine.
- Install PHPCS at the project level so that PHPCS is available only when working within that project directory.
- Install PHPCS in a locally cloned wpcomvip GitHub repository using the configurations defined in
Refer to the PHP_CodeSniffer Wiki for more comprehensive guidance on using PHPCS.
Following the instructions for installing PHPCS for WordPress VIP will also install the
dealerdirect/phpcodesniffer-composer-installer Composer plugin package in the background.
The presence of the
dealerdirect/phpcodesniffer-composer-installer Composer plugin package allows standards to be automatically registered with PHPCS. This eliminates the need to register standards separately when new standards are added.
A list of installed standards can be returned by running the command
phpcs -i. After following the instructions for installation either globally or at the project level, the returned standards should match this example:
$ phpcs -i The installed coding standards are MySource, PEAR, PSR1, PSR2, PSR12, Squiz, Zend, WordPress-VIP-Go, WordPressVIPMinimum, Modernize, NormalizedArrays, Universal, PHPCSUtils, VariableAnalysis, WordPress, WordPress-Core, WordPress-Docs and WordPress-Extra
WordPress-VIP standard should not appear in the returned list. This standard has been deprecated, is not used in the latest version of VIPCS, and has been removed completely from WordPressCS 2.x.
Integrating PHPCS into a code editor or IDE
VIP recommends integrating PHPCS inside code editors or IDEs to receive PHPCS feedback in real time during development.
Many popular code editors provide documentation for integrating PHPCS.
- Visual Studio Code (VS Code): Multiple plugins are available for integrating PHPCS with VS Code.
- PHPStorm: Documentation for integrating PHPCS in PHPStorm.
- Sublime Text: The SublimeLinter-phpcs plugin and the sublime-phpcs plugin for Sublime Text.
It is also possible to run PHPCS in a Continuous Integration build process (e.g. Circle CI). This method enables issues to be reported against any pull requests and for reports of issues to be sent via email and other channels.
Last updated: January 10, 2024