ground / coding-standard
Coding standard
Installs: 16
Dependents: 2
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 0
Open Issues: 0
Type:phpcodesniffer-standard
Requires
- php: ^7.1
- dealerdirect/phpcodesniffer-composer-installer: ^0.6.2 || ^0.7
- slevomat/coding-standard: ^6.2.0
- squizlabs/php_codesniffer: ^3.5.3
- webimpress/coding-standard: ^1.1.5
README
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
-
Install the module via composer by running:
$ composer require --dev ground/coding-standard
-
Add composer scripts into your
composer.json
:"scripts": { "cs-check": "phpcs", "cs-fix": "phpcbf" }
-
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: