Run PHPCS against code
Running a PHPCS scan against code, particularly third-party plugins and themes, can provide useful and actionable feedback on existing warnings and errors within the code.
Refer to the PHP_CodeSniffer Wiki for additional guidance on scanning code with PHPCS.
Prerequisite
PHPCS is installed on the user’s local machine as well as the WordPress Coding Standards and the VIP Coding Standards.
The following command example sets the appropriate standard (WordPress-VIP-Go), tells PHPCS to show the violation code for any violations(-s), show a progress bar (-p), cut the file paths down to be relative from the current directory (--basepath=.), and to ignore the vendor/ directory.
phpcs --standard=WordPress-VIP-Go -sp --basepath=. --ignore=vendor path/to/code/directory
Path to the directory or file to be scanned
PHPCS scans can be run against the contents of a directory or against a single file. The path value in a PHPCS command can be an absolute path or a relative path to the directory from which the PHPCS command is run.
If the user is in the directory Desktop in the terminal prompt, and the example-site repository has been cloned to Desktop/working-folder/example-site, the repository’s path value in the command will be working-folder/example-site.
Format command output
Command output can be formatted as a specific “Report Type”, and limited to specific ranges of severity levels. This command example demonstrates how to format the command output in columns as a CSV, and only output errors and warnings of severity level 6 or higher:
phpcs --standard=WordPress-VIP-Go -sp --basepath=. --ignore=vendor --warning-severity=6 --error-severity=6 --report=csv /path/to/code/directory/ | column -t -s, | less -S
Run PHPCS in a code editor or IDE
It is recommended to integrate PHPCS inside of code editors or integrated development environments (IDEs) in order 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. GitHub Actions). This method enables issues to be reported against any pull requests and for reports of issues to be sent via email and other channels.
Troubleshooting
A PHPCS scan might fail due to memory exhaustion when run against large amounts of code. To resolve this issue, scan smaller amounts of code (e.g. one plugin directory at a time).
Last updated: December 31, 2025