PHP_CodeSniffer

Web Sitehttp://pear.php.net/package/PHP_CodeSniffer
LanguagePHP
Supported Version2.9.1, 3.0.2

Getting Started

To start using PHP_CodeSniffer, enable it in repository setting. To customize standard you want to follow, add sideci.yml in your repository and write down your desired standard in it.

linter:
  code_sniffer:
    options:
      standard: CakePHP
      dir: app/

Analyzer Version, 2 or 3

SideCI assumes you are using PHP_CodeSniffer 2.9, for compatibility. If you want to use version 3, declare that in sideci.yml.

linter:
  code_sniffer:
    version: 3

Default Configuration

SideCI tries to detect standard and target directory for your project automatically when you specifies nothing in sideci.yml. If it cannot find appropriate standard, it assumes PSR2 as its standard and analyzes all PHP files in your repository.

Standard and Analysis Target

SideCI tries to detect the most suitable standard and target directory for your project, based on the framework your project is using.

When you are using CodeSniffer version 2, the following standards can be auto-detected:

When you are using CodeSniffer version 3, CakePHP is the only one standard which can be auto-detected.

The autodetection is based on file and directory structure. For the case auto detection fails, you can specify standard in sideci.yml.

Configuration via sideci.yml

Example setting for PHP_CodeSniffer under code_sniffer is the following:.

linter:
  code_sniffer:
    version: 3
    options:
      standard: ruleset.xml
      dir: app/
      extensions: php,inc,lib
      encoding: utf-8

version

This option controls version of PHP_CodeSniffer in running. Default value is 2.

options

This option controls command line options given to phpcs.

standard

This option controls coding standard of your project. If you leave this value absent, SideCI tries to detect standard automatically.

PSR2 is used when auto detection fails.

You available your custom ruleset to declare it in a standard like /path/to/MyStandard. Furthermore, you can use other standards which PHP_CodeSniffer supports below:

$ phpcs -i
The installed coding standards are FuelPHP, Symfony2, CodeIgniter, CakePHP, PEAR, Zend, Squiz, PSR2, PHPCS, PSR1, MySource, WordPress-Docs, WordPress-Extra, WordPress-VIP, WordPress and WordPress-Core
$ phpcs3 -i
The installed coding standards are MySource, PEAR, PSR1, PSR2, Squiz, Zend and CakePHP

dir

This option controls directories SideCI inspects. The default value is depended on frameworks PHP_CodeSniffer supports.
If you use no frameworks or use any frameworks PHP_CodeSniffer does not support, ./ is adopted by default.

In case you would like to exclude specific directories, you should write it in your custom ruleset file.

extensions

This option controls extensions of files SideCI inspects. The default value is php.

encoding

This option controls file encoding.

Future Support for PHP_CodeSniffer 2 in SideCI

SideCI has a plan to run with version 2 by default for a while. However, PHP_CodeSniffer says that version 2 is released to serious bug and security fixes only and that new features are developed for only after version 3. Thus we recommend you to use version 3 in a case of some reasons.