Skip to content

Commit 85382c0

Browse files
committed
🔧 QA: add code style check for the code in this repo
This: * Adds a custom PHPCS ruleset which uses the `PHPCSDev` ruleset to check the code style of code in this repo. * Adds convenience scripts to the `composer.json` file to check the code of the repo. * And allows for individual developers to overload the `phpcs.xml.dist` file by ignoring the typical overload files.
1 parent 31ed3d6 commit 85382c0

6 files changed

Lines changed: 58 additions & 0 deletions

File tree

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
/.gitattributes export-ignore
99
/.gitignore export-ignore
1010
/.travis.yml export-ignore
11+
/phpcs.xml.dist export-ignore
1112

1213
#
1314
# Auto detect text files and perform LF normalization

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
vendor/
22
composer.lock
3+
.phpcs.xml
4+
phpcs.xml

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ jobs:
3131
packages:
3232
- libxml2-utils
3333
script:
34+
# Check the code style of the code base.
35+
- composer check-cs
36+
3437
# Validate the xml file.
3538
# @link http://xmlsoft.org/xmllint.html
3639
- xmllint --noout --schema ./vendor/squizlabs/php_codesniffer/phpcs.xsd ./PHPCSDev/ruleset.xml
@@ -46,6 +49,7 @@ before_install:
4649
- export XMLLINT_INDENT=" "
4750

4851
# --prefer-dist will allow for optimal use of the travis caching ability.
52+
# The Composer PHPCS plugin takes care of setting the installed_paths for PHPCS.
4953
- composer install --prefer-dist --no-suggest
5054

5155

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ The standard checks your code against the following:
9292

9393
The ruleset can be used like any other ruleset and specific sniffs and settings can be added to or overruled from a custom project based ruleset.
9494

95+
For an example project-based ruleset using the `PHCPSDev` standard, have a look at the [`phpcs.xml.dist` file](https://github.com/PHPCSStandards/PHPCSDevTools/blob/develop/phpcs.xml.dist) in this repo.
96+
9597

9698
Contributing
9799
-------

composer.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@
3333
"scripts" : {
3434
"lint": [
3535
"@php ./vendor/jakub-onderka/php-parallel-lint/parallel-lint . -e php --exclude vendor"
36+
],
37+
"check-cs": [
38+
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcs"
39+
],
40+
"fix-cs": [
41+
"@php ./vendor/squizlabs/php_codesniffer/bin/phpcbf"
3642
]
3743
}
3844
}

phpcs.xml.dist

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0"?>
2+
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="Coding Standard for PHPCSDevTools" xsi:noNamespaceSchemaLocation="./vendor/squizlabs/php_codesniffer/phpcs.xsd">
3+
<description>Check the code of the PHPCSDevTools standard itself.</description>
4+
5+
<!--
6+
#############################################################################
7+
COMMAND LINE ARGUMENTS
8+
https://github.com/squizlabs/PHP_CodeSniffer/wiki/Annotated-ruleset.xml
9+
#############################################################################
10+
-->
11+
12+
<file>.</file>
13+
14+
<!-- Exclude Composer vendor directory. -->
15+
<exclude-pattern>*/vendor/*</exclude-pattern>
16+
17+
<!-- Only check PHP files. -->
18+
<arg name="extensions" value="php"/>
19+
20+
<!-- Show progress, show the error codes for each message (source). -->
21+
<arg value="ps"/>
22+
23+
<!-- Strip the filepaths down to the relevant bit. -->
24+
<arg name="basepath" value="./"/>
25+
26+
<!-- Check up to 8 files simultaneously. -->
27+
<arg name="parallel" value="8"/>
28+
29+
<!--
30+
#############################################################################
31+
USE THE PHPCSDev RULESET
32+
#############################################################################
33+
-->
34+
35+
<rule ref="PHPCSDev"/>
36+
37+
<!-- Set minimum PHP version supported to PHP 5.4. -->
38+
<config name="testVersion" value="5.4-"/>
39+
40+
<!-- Enforce short arrays. -->
41+
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
42+
43+
</ruleset>

0 commit comments

Comments
 (0)