Title: Run PHPCS against code
Author: WordPress VIP Documentation
Published: September 4, 2023
Last modified: December 31, 2025

---

 1. [PHPCS for WordPress VIP](https://docs.wpvip.com/php_codesniffer/)
 2. Run PHPCS against code

#  Run PHPCS against code

[Running a PHPCS scan](https://docs.wpvip.com/php_codesniffer/) against code, particularly
third-party plugins and themes, can provide useful and actionable [feedback on existing warnings and errors](https://docs.wpvip.com/vip-code-analysis-bot/phpcs-report/)
within the code.

Refer to [the PHP_CodeSniffer Wiki](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Usage)
for additional guidance on scanning code with PHPCS.

**Prerequisite**

[PHPCS is installed](https://docs.wpvip.com/php_codesniffer/) on the user’s local
machine as well as the [WordPress Coding Standards](https://github.com/WordPress/WordPress-Coding-Standards)
and the [VIP Coding Standards](https://github.com/Automattic/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.

    ```wp-block-preformatted
    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”](https://github.com/squizlabs/PHP_CodeSniffer/wiki/Reporting),
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:

    ```wp-block-preformatted
    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](https://marketplace.visualstudio.com/search?term=phpcs&target=VSCode&category=All%20categories&sortBy=Relevance).
 * **PHPStorm**: [Documentation for integrating PHPCS in PHPStorm.](https://www.jetbrains.com/help/phpstorm/2019.1/using-php-code-sniffer.html)
 * **Sublime Text:** [The SublimeLinter-phpcs plugin](https://github.com/SublimeLinter/SublimeLinter-phpcs)
   and [the sublime-phpcs plugin](https://github.com/benmatselby/sublime-phpcs) 
   for Sublime Text.

It is also possible to run PHPCS in a Continuous Integration build process (e.g.
[GitHub Actions](https://docs.wpvip.com/code-deployment/github-repository/#0-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