PHP Code Sniffer

Language: PHP
Checks: 212
Categories: Style
PHP_CodeSniffer Version: 2.8.1

Our PHP Code Sniffer engine helps you detect violations of a defined coding standard.

It wraps the PHP_CodeSniffer static analysis tool. You can run it on your command line using the Code Climate CLI, or on our hosted analysis platform.

Enable the Plugin

To enable PHP Code Sniffer analysis, add the following to your .codeclimate.yml configuration file:

plugins:
  phpcodesniffer:
    enabled: true

More information about the CLI is available in the README here: https://github.com/codeclimate/codeclimate

Configure the Plugin

Extensions

You can specify which file extensions you'd like our PHP Code Sniffer engine to analyze by adding a file_extensions key nested under an engine config key in your .codeclimate.yml:

plugins:
  phpcodesniffer:
    enabled: true
    config:
      file_extensions: "php,inc,lib"

Standard

You can specify a list of standards that you want PHP Code Sniffer to use while analyzing your files by adding a standard key, nested under an engine config key in your .codeclimate.yml:

In addition to PSR1 and PSR2, our engine supports a select number of additional coding standards:

  • Drupal
  • DrupalPractice
  • Magento 1 (MEQP1)
  • Magento 2 (MEQP2)
  • MySource
  • PEAR
  • PHPCS
  • Squiz
  • WordPress
  • WordPress-Core
  • WordPress-Docs
  • WordPress-Extra
  • WordPress-VIP
  • Zend
plugins:
  phpcodesniffer:
    enabled: true
    config:
    	standard: "PSR1,PSR2"

Ignore Warnings

You can configure our PHP Code Sniffer engine to hide warnings, and only report errors with this option by adding an ignore_warnings key, nested under an engine config key in your .codeclimate.yml:

plugins:
  phpcodesniffer:
    enabled: true
    config:
      ignore_warnings: true

Custom Plugin

Custom sniffs must be accessible to the repository being analyzed, either by being committed to the repo directly or committed via a git submodule.

To use our submodule support, simply specify checkout_submodules: true in the top level of a committed .codeclimate.yml file. We'll then attempt to checkout submodules before running analysis. Note that:

  • this call is not recursive
  • will only checkout 1 level deep.

Understand the Plugin

To learn more about the format for the values for these config options, check out PHP_CodeSniffer's documentation

PHP Code Sniffer


Suggested Edits are limited on API Reference Pages

You can only suggest edits to Markdown body content, but not to the API spec.