Skip to content

PHPCS for WordPress VIP

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:

Refer to the PHP_CodeSniffer Wiki for more comprehensive guidance on using PHPCS.

Installed standards

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

Note

The 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.

The current VIP-Coding-Standards (VIPCS) 3.x release requires at minimum WordPress-Coding-Standards (WordPressCS) 3.x. Refer to the README for the exact minimum version required.

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.

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

Relevant to

  • WordPress