Skip to content

Latest commit

 

History

History
152 lines (103 loc) · 3.41 KB

phpcs.md

File metadata and controls

152 lines (103 loc) · 3.41 KB

Phpcs

The Phpcs task will sniff your code for bad coding standards. It lives under the phpcs namespace and has following configurable parameters:

# grumphp.yml
parameters:
    tasks:
        phpcs:
            standard: ~
            show_warnings: true
            tab_width: ~
            whitelist_patterns: []
            encoding: ~
            ignore_patterns: []
            sniffs: []
            triggered_by: [php]
            

standard

Default: null

This parameter will describe which standard is being used to validate your code for bad coding standards. By default it is set to null so that the Phpcs defaults are being used. Phpcs will be using the PEAR or local phpcs.xml standard by default. You can configure this task to use any standard supported by the Phpcs CLI. For Example: PEAR, PHPCS, PSR1, PSR2, Squiz and Zend

You can get a list of all installed phpcs standards with the command:

phpcs -i

show_warnings

Default: true

Triggers an error when there are warnings.

tab_width

Default: null

By default, the standard will specify the optimal tab-width of the code. If you want to overwrite this option, you can use this configuration option.

encoding

Default: null

The default encoding used by PHP_CodeSniffer (is ISO-8859-1).

whitelist_patterns

Default: []

This is a list of regex patterns that will filter files to validate. With this option you can skip files like tests. This option is used in relation with the parameter triggered_by. For exemple to validate only files in your src/App/ and src/AppBundle/ directories in a Symfony you can use

whitelist_patterns:
  - /^src\/App\/(.*)/
  - /^src\/AppBundle\/(.*)/

ignore_patterns

Default: []

This is a list of patterns that will be ignored by phpcs. With this option you can skip files like tests. Leave this option blank to run phpcs for every php file.

sniffs

Default: []

This is a list of sniffs that need to be executed. Leave this option blank to run all configured sniffs for the selected standard.

triggered_by

*Default: [php]:

This is a list of extensions to be sniffed.

Framework presets

Symfony 2

If you want to use Phpcs for your Symfony2 projects, you can require the leanpub phpcs repo.

composer require --dev leaphub/phpcs-symfony2-standard

Following this, you can add the path to your phpcs task.

# grumphp.yml
parameters:
    tasks:
        phpcs:
            standard: "vendor/leaphub/phpcs-symfony2-standard/leaphub/phpcs/Symfony2/"

Magento

If you want to use Phpcs for your Magento projects, you can require the magento-ecg repo.

composer require --dev magento-ecg/coding-standard

Following this, you can add the path to your phpcs task.

# grumphp.yml
parameters:
    tasks:
        phpcs:
            standard: "vendor/magento-ecg/coding-standard/Ecg/"
            show_warnings: false

Drupal

If you want to use Phpcs for your Drupal projects, you can require the Drupal Code Sniffer (Coder)

composer require --dev drupal/coder

Following this, you can add the path to your phpcs task.

# grumphp.yml
parameters:
    tasks:
        phpcs:
            standard: vendor/drupal/coder/coder_sniffer/Drupal/
            ignore_patterns:
              - cfg/
              - libraries/
            triggered_by:
              - php
              - module
              - inc