Skip to content

Commit

Permalink
Merge pull request #7 from MichelHartmann/cross-platform-support
Browse files Browse the repository at this point in the history
Cross platform support
  • Loading branch information
MichelHartmann authored Oct 13, 2017
2 parents 45eacdb + 860657e commit 78b63db
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 15 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2017, Flyeralarm Digital GmbH
Copyright (c) 2017, FLYERALARM Digital GmbH
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
44 changes: 34 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Flyeralarm PHP Coding Guideline Validator
# FLYERALARM PHP Coding Guideline Validator


This repository contains the ruleset for the PHP code we develop at [FLYERALARM](https://flyeralarm.com).
Expand All @@ -10,7 +10,8 @@ It mostly consists of PSR-2 with some custom additions. The rules are enforced w
* Variable names must be in lowerCamelCase
* Yoda conditions are forbidden
* Unit tests with @expectedException must contain @expectedExceptionMessage annotation
* Return type annotations (@return) must only contain one of scalar type or object (e.g. no "@return string|null")
* Return type annotations (@return) must only contain one of scalar type, object (e.g. no "@return string|null") or
an array of one these
* Exceptions messages must not contain exclamation marks or full stops
* Keywords GOTO and EVAL are forbidden
* Underscores in namespaces are forbidden
Expand All @@ -19,12 +20,12 @@ It mostly consists of PSR-2 with some custom additions. The rules are enforced w

## How-To work within *this* project
To prepare run command:
```
```bash
make
```

To test ruleset run command:
```
```bash
make test
```

Expand All @@ -37,25 +38,48 @@ composer config repositories.flyeralarm/php-code-validator git https://github.co
composer require --dev flyeralarm/php-code-validator
```

Embed code sniffer in your Makefile. To intend please use tabs instead of spaces. \
_Usage:_ vendor/bin/php-code-validator <folder-to-test-one> <folder-to-test-two> <...>
Embed code sniffer in your Makefile. To intend please use tabs instead of spaces.

Example Makefile:
```
```make
test:
vendor/bin/php-code-validator src/ tests/
vendor/bin/phpcs -w -p -s --standard=vendor/flyeralarm/php-code-validator/ruleset.xml src/ tests/
```

### Add project specific rules
The recommended way to define custom rules for the own project is to provide a ```phpcs.xml``` in the root of your
project.
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)).

This ```phpcs.xml``` can then reference the FLYERALARM PHP coding standard.
```xml
<?xml version="1.0" encoding="UTF-8" ?>
<ruleset name="Project Rules">
<file>./src/</file>
<file>./tests/</file>
<arg value="sp"/>

<rule ref="vendor/flyeralarm/php-code-validator/ruleset.xml"/>

<!-- custom rules -->

</ruleset>
```

Once the file ```phpcs.xml``` is created the code can be validated using:
```bash
vendor/bin/phpcs
```

### Update to latest stable

```
```bash
composer update flyeralarm/php-code-validator
```


### Run sniffer
```
```bash
make test
```

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "flyeralarm/php-code-validator",
"description": "A custom coding standard for flyeralarm",
"description": "A custom coding standard for FLYERALARM",
"type": "config",
"license": "proprietary",
"authors": [
Expand Down
4 changes: 2 additions & 2 deletions ruleset.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0"?>
<ruleset name="Flyeralarm Coding Guidelines">
<description>A custom coding standard for flyeralarm</description>
<ruleset name="FLYERALARM Coding Guidelines">
<description>A custom coding standard for FLYERALARM</description>
<rule ref="PSR2"/>
<rule ref="Generic.Formatting.SpaceAfterCast"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax.Found"/>
Expand Down
9 changes: 8 additions & 1 deletion tests/runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,14 @@ function processDir($dirPath)
}

$fileContent = file_get_contents($dirPath . $file);
$snifferOutput = shell_exec(__DIR__ . '/../bin/php-code-validator "' . $dirPath . $file . '"');
$snifferOutput = shell_exec(
sprintf(
"%s -w -p -s --standard=%s %s",
escapeshellcmd(__DIR__ . '/../vendor/bin/phpcs'),
escapeshellarg(__DIR__ . '/../ruleset.xml'),
escapeshellarg($dirPath . $file)
)
);

// expectedPass
if (preg_match('|//\s@expectedPass$|m', $fileContent)) {
Expand Down

0 comments on commit 78b63db

Please sign in to comment.