dev-master
9999999-dev https://charcoal.locomotive.ca/Charcoal Coding Standard
MIT
The Requires
- php >=5.6.0 || >=7.0
- squizlabs/php_codesniffer ^3.3
The Development Requires
by Locomotive
coding standard sniffer charcoal
Charcoal Coding Standard
![License][badge-license] ![Build Status][badge-travis], (*1)
The PHP_CodeSniffer ruleset to check that repositories are following the standards used by the Charcoal framework., (*2)
The Charcoal Coding Standard extends and expands PSR-1 and PSR-2 ~~PSR-12~~., (*3)
For a full reference of enforcements, please consult Charcoal/ruleset.xml
., (*4)
You can install the Charcoal Coding Standard as a Composer dependency of your project., (*5)
Install the package via Composer:, (*6)
$ composer require --dev locomotivemtl/charcoal-coding-standard
Register the new standard with PHP_CodeSniffer:, (*7)
$ ./vendor/bin/phpcs --config-set installed_paths ./vendor/locomotivemtl/charcoal-coding-standard
The second command registers the standard with phpcs
.
Ensure existing values of the installed_paths
option are not overwritten., (*8)
Create a phpcs.xml
file at the base of your repository with the following content:, (*9)
<?xml version="1.0"?> <ruleset name="Charcoal Package"> <rule ref="Charcoal" /> </ruleset>
You can include or exclude sniffs from this file. For a reference of customizations, consult the PHP_CodeSniffer annotated ruleset., (*10)
Note: If you did not register the Charcoal Coding Standard with PHP_CodeSniffer, you can reference the standard using its path instead of its name:, (*11)
<rule ref="./vendor/locomotivemtl/charcoal-coding-standard/Charcoal/ruleset.xml" />Example:
phpcs.xml.example
., (*12)
Add scripts to your composer.json
:, (*13)
"scripts": { "cs-check": "phpcs --colors -p ./src ./tests", "cs-fix": "phpcbf --colors ./src ./tests" }
You can also install the Charcoal Coding Standard system-wide:, (*14)
Install the package via Composer:, (*15)
$ composer global require locomotivemtl/charcoal-coding-standard
Register the new standard with PHP_CodeSniffer:, (*16)
$ phpcs --config-set installed_paths ~/.composer/vendor/locomotivemtl/charcoal-coding-standard
The second command registers the standard with phpcs
.
Ensure existing values of the installed_paths
option are not overwritten., (*17)
Depending on how you installed the Charcoal Coding Standard, you can do the following:, (*18)
Detect violations of this standard with one of:, (*19)
$ phpcs --standard=Charcoal /path/to/some/file/to/sniff.php $ ./vendor/bin/phpcs --standard=Charcoal /path/to/some/file/to/sniff.php $ composer cs-check
Automatically fix violations of this standard with:, (*20)
$ phpcbf --standard=Charcoal /path/to/some/file/to/sniff.php $ ./vendor/bin/phpcbf --standard=Charcoal /path/to/some/file/to/sniff.php $ composer cs-fix
For further usage options, see the CLI documentation., (*21)
Note: If you did not register the Charcoal Coding Standard with PHP_CodeSniffer, you can reference the standard using its path instead of its name:, (*22)
$ ./vendor/bin/phpcs --standard=./vendor/locomotivemtl/charcoal-coding-standard /path/to/code
The Charcoal Coding Standard provides a simple but convenient bash script wrapper around php -l
to recursively perform syntax checks on PHP files with several processes at once., (*23)
Usage: phplint [options] [<path>]... Arguments: path One or more paths to files or directories to search for PHP files. Defaults to ./src and ./tests. Options: -h, --help Display this help message and exit. -V, --version Display version information and exit.
Example:, (*24)
$ phplint src/Http/Controllers/ src/Providers/RouteServiceProvider.php
Note: The script is not part of the
composer.json
; it is not added to the given project when the package is installed. The script must be called from the vendor package or you must manually symlink it into yourbin-dir
., (*25)
You can run the script from your project:, (*26)
$ ./vendor/locomotivemtl/charcoal-coding-standard/bin/phplint ./src ./testsYou can also symlink the script into your project's
bin-dir
:, (*27)$ cd $(composer config bin-dir) $ ln -s ../locomotivemtl/charcoal-coding-standard/bin/phplint ./phplintCheck out overtrue/phplint, a more advanced and configurable tool for linting PHP files., (*28)
Charcoal is licensed under the MIT license. See LICENSE for details., (*29)
Charcoal Coding Standard
MIT
coding standard sniffer charcoal