ground/coding-standard

Coding standard

Installs: 16

Dependents: 2

Suggesters: 0

Security: 0

Stars: 0

Watchers: 2

Forks: 0

Open Issues: 0

Type:phpcodesniffer-standard

1.0.13 2020-07-27 10:46 UTC

This package is auto-updated.

Last update: 2024-04-27 19:09:29 UTC


README

Build Status

The coding standard ruleset

This specification extends and expands PSR-12, the extended coding style guide and requires adherence to PSR-1, the basic coding standard.

Installation

  1. Install the module via composer by running:

    $ composer require --dev ground/coding-standard
  2. Add composer scripts into your composer.json:

    "scripts": {
      "cs-check": "phpcs",
      "cs-fix": "phpcbf"
    }
  3. Create phpcs.xml file on base path of your repository:

    <?xml version="1.0"?>
    <ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">
    
        <arg name="basepath" value="."/>
        <arg name="cache" value=".phpcs-cache"/>
        <arg name="colors"/>
        <arg name="extensions" value="php"/>
        <arg name="parallel" value="80"/>
        
        <!-- Show progress -->
        <arg value="p"/>
    
        <!-- Paths to check -->
        <file>config</file>
        <file>src</file>
        <file>test</file>
    
        <!-- Include all rules from the Coding Standard -->
        <rule ref="CodingStandard"/>
    </ruleset>

You can add or exclude some locations in that file. For a reference please see: https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-Ruleset

Usage

  • To run checks only:

    $ composer cs-check
  • To automatically fix many CS issues:

    $ composer cs-fix

Ignoring parts of a File

Disable parts of a file:

$xmlPackage = new XMLPackage;
// phpcs:disable
$xmlPackage['error_code'] = get_default_error_code_value();
$xmlPackage->send();
// phpcs:enable

Disable a specific rule:

// phpcs:disable Generic.Commenting.Todo.Found
$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// TODO: Add an error message here.
$xmlPackage->send();
// phpcs:enable

Ignore a specific violation:

$xmlPackage = new XMLPackage;
$xmlPackage['error_code'] = get_default_error_code_value();
// phpcs:ignore Generic.Commenting.Todo.Found
// TODO: Add an error message here.
$xmlPackage->send();

Reference

Rules can be added, excluded or tweaked locally, depending on your preferences. More information on how to do this can be found here: