PHP_CodeSniffer
Supported Version | Language | Website |
---|---|---|
3.5.8 | PHP | https://pear.php.net/package/PHP_CodeSniffer |
PHP_CodeSniffer is a style checker to enforce a defined set of PHP coding standards.
Getting Started
To start using PHP_CodeSniffer, enable it in your repository settings.
To configure the coding standard you want to follow, add sider.yml
in your repository and set the standard
option:
linter:
code_sniffer:
dir: app/
standard: CakePHP
Default Configuration
If you don't specify anything, Sider tries to detect the standard and target directory for your project automatically.
If it cannot find an appropriate standard, it assumes PSR2
as its standard and analyzes all PHP files in your repository.
Standard and Analysis Target
Sider tries to detect the most suitable standard and target directory for your project, based on the framework your project is using.
The following standards are detected automatically:
CakePHP
Symfony
The auto-detection is based on file names and directory structure in your repository.
If this auto-detection fails, you can specify a standard in sider.yml
.
sider.yml
Configuration via An example setting for PHP_CodeSniffer under code_sniffer
:
linter:
code_sniffer:
dir: app/
standard: phpcs.xml
extensions: php,inc,lib
encoding: utf-8
ignore:
- app/vendor
- test/ignored.php
You can use several options to fine-tune PHP_CodeSniffer to your project:
Name | Type | Default |
---|---|---|
root_dir | string | - |
dir | string | . |
standard | string | PSR2 |
extensions | string , string[] | php |
encoding | string | - |
ignore | string , string[] | [] |
dir
This option controls directories to be analyzed. The default value is dependent on the frameworks PHP_CodeSniffer supports.
If you are not using any frameworks or are using a framework PHP_CodeSniffer does not support, .
is used.
If you would like to exclude specific directories, you can specify them in a custom ruleset file.
standard
This option controls a coding standard of your project. If you leave this value empty, Sider tries to detect the standard automatically.
PSR2
is used when auto detection fails.
You can use the following third-party standards in addition to the standards which PHP_CodeSniffer supports natively:
If you want to see the actual standard lists, run the command phpcs -i
.
The following output is a standard list that we prepare.
$ phpcs -i
The installed coding standards are Zend, PSR12, MySource, Squiz, PSR2, PSR1, PEAR, CakePHP, Symfony, WordPress, WordPress-Extra, WordPress-Docs and WordPress-Core
You can also define your own standard, and enter the path to the config file here.
extensions
This option controls a comma-separated list of file extensions to be analyzed. You also can specify an array of extensions.
encoding
This option controls an encoding of files to be analyzed.
ignore
This option controls a comma-separated list of file or directory patterns to be ignored. You also can specify an array of patterns.