From 330ab0947fe0214a2608541f7bf0364fbba5ff4d Mon Sep 17 00:00:00 2001 From: Michel Hartmann Date: Wed, 11 Oct 2017 19:46:34 +0200 Subject: [PATCH 1/2] * added support for windows by calling phpcs directly --- tests/runner.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/runner.php b/tests/runner.php index e75e816..a546361 100644 --- a/tests/runner.php +++ b/tests/runner.php @@ -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)) { From 860657e11d97708fd10beecdac0c1568928754d5 Mon Sep 17 00:00:00 2001 From: Michel Hartmann Date: Wed, 11 Oct 2017 19:49:18 +0200 Subject: [PATCH 2/2] * fixed naming of FLYERALARM * describe a recommended way to extend the ruleset * improved rendering of code samples --- LICENSE | 2 +- README.md | 44 ++++++++++++++++++++++++++++++++++---------- composer.json | 2 +- ruleset.xml | 4 ++-- 4 files changed, 38 insertions(+), 14 deletions(-) diff --git a/LICENSE b/LICENSE index d9f68e2..7ee43ec 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/README.md b/README.md index 0841ce3..691f717 100644 --- a/README.md +++ b/README.md @@ -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). @@ -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 @@ -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 ``` @@ -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 <...> +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 + + + ./src/ + ./tests/ + + + + + + + ``` +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 ``` diff --git a/composer.json b/composer.json index afe6aba..bfdfcdf 100644 --- a/composer.json +++ b/composer.json @@ -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": [ diff --git a/ruleset.xml b/ruleset.xml index 461f507..414afe4 100644 --- a/ruleset.xml +++ b/ruleset.xml @@ -1,6 +1,6 @@ - - A custom coding standard for flyeralarm + + A custom coding standard for FLYERALARM