PHP Code Sniffer

150150

Language: PHP
Checks: 212
Categories: Style
PHP_CodeSniffer Version: 2.9.1 (version 3.6.0 available using beta channel)

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:

plugins:
  phpcodesniffer:
    enabled: true
    config:
        standard: "PSR1,PSR2"

You can also indicate PHP CodeSniffer to use custom external rule set by specifying the relative path to the rules set's root directory on the command line.

plugins:
  phpcodesniffer:
    enabled: true
    config:
        standard: "my_custom_php_ruleset.xml"

📘

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

Our stable version of PHP Codesniffer includes the standards listed above.

  • To use the PSR12 standard, you'll need to specify the beta channel in your .codeclimate.yml:

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

Understand the Plugin

📘

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