1- # Flyeralarm PHP Coding Guideline Validator
1+ # FLYERALARM PHP Coding Guideline Validator
22
33
44This repository contains the ruleset for the PHP code we develop at [ FLYERALARM] ( https://flyeralarm.com ) .
@@ -10,7 +10,8 @@ It mostly consists of PSR-2 with some custom additions. The rules are enforced w
1010* Variable names must be in lowerCamelCase
1111* Yoda conditions are forbidden
1212* Unit tests with @expectedException must contain @expectedExceptionMessage annotation
13- * Return type annotations (@return ) must only contain one of scalar type or object (e.g. no "@return string|null")
13+ * Return type annotations (@return ) must only contain one of scalar type, object (e.g. no "@return string|null") or
14+ an array of one these
1415* Exceptions messages must not contain exclamation marks or full stops
1516* Keywords GOTO and EVAL are forbidden
1617* Underscores in namespaces are forbidden
@@ -19,12 +20,12 @@ It mostly consists of PSR-2 with some custom additions. The rules are enforced w
1920
2021## How-To work within * this* project
2122To prepare run command:
22- ```
23+ ``` bash
2324make
2425```
2526
2627To test ruleset run command:
27- ```
28+ ``` bash
2829make test
2930```
3031
@@ -37,25 +38,48 @@ composer config repositories.flyeralarm/php-code-validator git https://github.co
3738composer require --dev flyeralarm/php-code-validator
3839```
3940
40- Embed code sniffer in your Makefile. To intend please use tabs instead of spaces. \
41- _ Usage:_ vendor/bin/php-code-validator <folder-to-test-one > <folder-to-test-two > <...>
41+ Embed code sniffer in your Makefile. To intend please use tabs instead of spaces.
4242
4343Example Makefile:
44- ```
44+ ``` make
4545test :
46- vendor/bin/php-code-validator src/ tests/
46+ vendor/bin/phpcs -w -p -s --standard=vendor/flyeralarm/php-code-validator/ruleset.xml src/ tests/
47+ ```
48+
49+ # ## Add project specific rules
50+ The recommended way to define custom rules for the own project is to provide a ```phpcs.xml``` in the root of your
51+ project.
52+ PHP_CodeSniffer will automatically detect this standard if no other standard was defined (See [PHP_CodeSniffer Advanced Usage](https ://github.com/squizlabs/PHP_CodeSniffer/wiki/Advanced-Usage# using-a-default-configuration-file)).
53+
54+ This ```phpcs.xml``` can then reference the FLYERALARM PHP coding standard.
55+ ```xml
56+ <?xml version="1.0" encoding="UTF-8" ?>
57+ <ruleset name="Project Rules">
58+ <file>./src/</file>
59+ <file>./tests/</file>
60+ <arg value="sp"/>
61+
62+ <rule ref="vendor/flyeralarm/php-code-validator/ruleset.xml"/>
63+
64+ <!-- custom rules -->
65+
66+ </ruleset>
4767```
4868
69+ Once the file ``` phpcs.xml ``` is created the code can be validated using:
70+ ``` bash
71+ vendor/bin/phpcs
72+ ```
4973
5074### Update to latest stable
5175
52- ```
76+ ``` bash
5377composer update flyeralarm/php-code-validator
5478```
5579
5680
5781### Run sniffer
58- ```
82+ ``` bash
5983make test
6084```
6185
0 commit comments