Skip to content

Commit 860657e

Browse files
* fixed naming of FLYERALARM
* describe a recommended way to extend the ruleset * improved rendering of code samples
1 parent 330ab09 commit 860657e

File tree

4 files changed

+38
-14
lines changed

4 files changed

+38
-14
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
BSD 3-Clause License
22

3-
Copyright (c) 2017, Flyeralarm Digital GmbH
3+
Copyright (c) 2017, FLYERALARM Digital GmbH
44
All rights reserved.
55

66
Redistribution and use in source and binary forms, with or without

README.md

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Flyeralarm PHP Coding Guideline Validator
1+
# FLYERALARM PHP Coding Guideline Validator
22

33

44
This 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
2122
To prepare run command:
22-
```
23+
```bash
2324
make
2425
```
2526

2627
To test ruleset run command:
27-
```
28+
```bash
2829
make test
2930
```
3031

@@ -37,25 +38,48 @@ composer config repositories.flyeralarm/php-code-validator git https://github.co
3738
composer 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

4343
Example Makefile:
44-
```
44+
```make
4545
test:
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
5377
composer update flyeralarm/php-code-validator
5478
```
5579

5680

5781
### Run sniffer
58-
```
82+
```bash
5983
make test
6084
```
6185

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "flyeralarm/php-code-validator",
3-
"description": "A custom coding standard for flyeralarm",
3+
"description": "A custom coding standard for FLYERALARM",
44
"type": "config",
55
"license": "proprietary",
66
"authors": [

ruleset.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0"?>
2-
<ruleset name="Flyeralarm Coding Guidelines">
3-
<description>A custom coding standard for flyeralarm</description>
2+
<ruleset name="FLYERALARM Coding Guidelines">
3+
<description>A custom coding standard for FLYERALARM</description>
44
<rule ref="PSR2"/>
55
<rule ref="Generic.Formatting.SpaceAfterCast"/>
66
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>

0 commit comments

Comments
 (0)