Skip to content
This repository was archived by the owner on Nov 23, 2019. It is now read-only.

Commit be309f9

Browse files
authored
Merge pull request #8 from acelaya/develop
Develop
2 parents 61ea01b + 4d91018 commit be309f9

21 files changed

+100
-25
lines changed

CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
## CHANGELOG
22

3+
### 2.1.1
4+
5+
**Enhancements:**
6+
7+
* [6: Improve coding styles using slevomat/coding-standard package](https://github.com/acelaya/ze-content-based-error-handler/issues/6)
8+
* [7: Add phpstan to build matrix](https://github.com/acelaya/ze-content-based-error-handler/issues/7)
9+
10+
**Bugs:**
11+
12+
* [6: Make ExceptionInterface extend Throwable ](https://github.com/acelaya/ze-content-based-error-handler/issues/6)
13+
314
### 2.1.0
415

516
**Enhancements:**

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Zend Expressive ContentBasedErrorResponseGenerator
22

3-
[![Build Status](https://travis-ci.org/acelaya/ze-content-based-error-handler.svg?branch=master)](https://travis-ci.org/acelaya/ze-content-based-error-handler)
4-
[![Code Coverage](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/?branch=master)
5-
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/?branch=master)
6-
[![Latest Stable Version](https://poser.pugx.org/acelaya/ze-content-based-error-handler/v/stable.png)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
7-
[![Total Downloads](https://poser.pugx.org/acelaya/ze-content-based-error-handler/downloads.png)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
8-
[![License](https://poser.pugx.org/acelaya/ze-content-based-error-handler/license.png)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
3+
[![Build Status](https://img.shields.io/travis/acelaya/ze-content-based-error-handler/master.svg?style=flat-square)](https://travis-ci.org/acelaya/ze-content-based-error-handler)
4+
[![Code Coverage](https://img.shields.io/scrutinizer/coverage/g/acelaya/ze-content-based-error-handler.svg?style=flat-square)](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/?branch=master)
5+
[![Scrutinizer Code Quality](https://img.shields.io/scrutinizer/g/acelaya/ze-content-based-error-handler.svg?style=flat-square)](https://scrutinizer-ci.com/g/acelaya/ze-content-based-error-handler/?branch=master)
6+
[![Latest Stable Version](https://poser.pugx.org/acelaya/ze-content-based-error-handler/v/stable?format=flat-square)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
7+
[![Total Downloads](https://poser.pugx.org/acelaya/ze-content-based-error-handler/downloads?format=flat-square)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
8+
[![License](https://poser.pugx.org/acelaya/ze-content-based-error-handler/license?format=flat-square)](LICENSE)
99

1010
A Zend Expressive error response generator which allows to implement different strategies to render error responses based on the accepted content-types.
1111

composer.json

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,15 @@
1111
],
1212
"require": {
1313
"php": "^7.1",
14-
"zendframework/zend-servicemanager": "^3.0",
15-
"zendframework/zend-expressive": "^2.0",
1614
"psr/log": "^1.0",
17-
"http-interop/http-middleware": "^0.4.1"
15+
"zendframework/zend-expressive": "^2.1",
16+
"zendframework/zend-servicemanager": "^3.0"
1817
},
1918
"require-dev": {
19+
"phpstan/phpstan": "^0.9.1",
2020
"phpunit/phpunit": "^6.0",
21-
"squizlabs/php_codesniffer": "^2.3"
21+
"slevomat/coding-standard": "^4.1",
22+
"squizlabs/php_codesniffer": "^3.1"
2223
},
2324
"license": "MIT",
2425
"authors": [
@@ -40,16 +41,21 @@
4041
"scripts": {
4142
"check": [
4243
"@cs",
44+
"@stan",
4345
"@test"
4446
],
4547
"cs": "phpcs",
4648
"cs-fix": "phpcbf",
49+
"stan": "phpstan analyse src/ --level=6",
4750
"test": "phpunit --coverage-clover build/clover.xml --colors=always",
4851
"pretty-test": "phpunit --coverage-html build/coverage"
4952
},
5053
"extra": {
5154
"zf": {
5255
"config-provider": "Acelaya\\ExpressiveErrorHandler\\ConfigProvider"
5356
}
57+
},
58+
"config": {
59+
"sort-packages": true
5460
}
5561
}

phpcs.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0"?>
22
<ruleset name="Coding standard">
3-
<description>Coding standard</description>
3+
<description>Coding standard specification</description>
4+
<config name="installed_paths" value="../../slevomat/coding-standard"/>
45

56
<!-- display progress -->
67
<arg value="p"/>
@@ -9,11 +10,35 @@
910
<!-- inherit rules from: -->
1011
<rule ref="PSR2"/>
1112
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
13+
<!-- Make sure string concatenations use 1 space between every element -->
14+
<rule ref="Squiz.Strings.ConcatenationSpacing">
15+
<properties>
16+
<property name="spacing" value="1"/>
17+
<property name="ignoreNewlines" value="true"/>
18+
</properties>
19+
</rule>
1220
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
1321
<properties>
1422
<property name="ignoreBlankLines" value="false"/>
1523
</properties>
1624
</rule>
25+
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
26+
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
27+
<properties>
28+
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
29+
<property name="spacesCountAroundEqualsSign" value="0"/>
30+
</properties>
31+
</rule>
32+
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
33+
<properties>
34+
<property name="searchAnnotations" value="true"/>
35+
</properties>
36+
</rule>
37+
<!-- Force strict comparison with === or !== instead of == or != -->
38+
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
39+
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
40+
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
41+
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
1742

1843
<!-- Paths to check -->
1944
<file>src</file>

src/ConfigProvider.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ContentBasedErrorResponseGenerator;

src/ErrorHandler/ContentBasedErrorResponseGenerator.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\ErrorHandler;
35

46
use Acelaya\ExpressiveErrorHandler\Exception\InvalidArgumentException;
@@ -50,13 +52,13 @@ public function __construct(
5052
/**
5153
* Final handler for an application.
5254
*
53-
* @param \Throwable $e
55+
* @param \Throwable|null $e
5456
* @param Request $request
5557
* @param Response $response
5658
* @return Response
5759
* @throws InvalidArgumentException
5860
*/
59-
public function __invoke($e, Request $request, Response $response): Response
61+
public function __invoke(?\Throwable $e, Request $request, Response $response): Response
6062
{
6163
// Try to get an error handler for provided request accepted type
6264
$errorHandler = $this->resolveErrorHandlerFromAcceptHeader($request);
Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\ErrorHandler;
35

4-
use Psr\Http\Message\ServerRequestInterface as Request;
56
use Psr\Http\Message\ResponseInterface as Response;
7+
use Psr\Http\Message\ServerRequestInterface as Request;
68

79
interface ErrorResponseGeneratorInterface
810
{
911
/**
1012
* Final handler for an application.
1113
*
12-
* @param \Throwable $e
14+
* @param \Throwable|null $e
1315
* @param Request $request
1416
* @param Response $response
1517
* @return Response
1618
*/
17-
public function __invoke($e, Request $request, Response $response);
19+
public function __invoke(?\Throwable $e, Request $request, Response $response);
1820
}

src/ErrorHandler/ErrorResponseGeneratorManager.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\ErrorHandler;
35

46
use Zend\ServiceManager\AbstractPluginManager;

src/ErrorHandler/ErrorResponseGeneratorManagerInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\ErrorHandler;
35

46
use Interop\Container\ContainerInterface;

src/ErrorHandler/Factory/ContentBasedErrorResponseGeneratorFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\ErrorHandler\Factory;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ContentBasedErrorResponseGenerator;

src/ErrorHandler/Factory/ErrorHandlerManagerFactory.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\ErrorHandler\Factory;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ErrorResponseGeneratorManager;

src/Exception/ExceptionInterface.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\Exception;
35

4-
interface ExceptionInterface
6+
interface ExceptionInterface extends \Throwable
57
{
6-
78
}

src/Exception/InvalidArgumentException.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\Exception;
35

46
class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface

src/Log/BasicLogMessageBuilder.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\Log;
35

46
use Psr\Http\Message\ResponseInterface as Response;
@@ -11,13 +13,13 @@ class BasicLogMessageBuilder implements LogMessageBuilderInterface
1113
*
1214
* @param Request $request
1315
* @param Response $response
14-
* @param null $err
16+
* @param \Throwable|null $err
1517
* @return string
1618
*/
17-
public function buildMessage(Request $request, Response $response, $err = null)
19+
public function buildMessage(Request $request, Response $response, \Throwable $err = null): string
1820
{
1921
$base = 'Error occurred while dispatching request';
20-
if (! isset($err)) {
22+
if ($err === null) {
2123
return $base;
2224
}
2325

src/Log/LogMessageBuilderInterface.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace Acelaya\ExpressiveErrorHandler\Log;
35

46
use Psr\Http\Message\ResponseInterface as Response;
@@ -11,8 +13,8 @@ interface LogMessageBuilderInterface
1113
*
1214
* @param Request $request
1315
* @param Response $response
14-
* @param null $err
16+
* @param \Throwable|null $err
1517
* @return string
1618
*/
17-
public function buildMessage(Request $request, Response $response, $err = null);
19+
public function buildMessage(Request $request, Response $response, \Throwable $err = null): string;
1820
}

test/ConfigProviderTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace AcelayaTest\ExpressiveErrorHandler;
35

46
use Acelaya\ExpressiveErrorHandler\ConfigProvider;

test/ErrorHandler/ContentBasedErrorHandlerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace AcelayaTest\ExpressiveErrorHandler\ErrorHandler;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ContentBasedErrorResponseGenerator;

test/ErrorHandler/ErrorHandlerManagerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace AcelayaTest\ExpressiveErrorHandler\ErrorHandler;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ErrorResponseGeneratorManager;
@@ -21,7 +23,7 @@ public function setUp()
2123
],
2224
'invokables' => [
2325
'invalid' => \stdClass::class,
24-
]
26+
],
2527
]);
2628
}
2729

test/ErrorHandler/Factory/ContentBasedErrorHandlerFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace AcelayaTest\ExpressiveErrorHandler\ErrorHandler\Factory;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ContentBasedErrorResponseGenerator;

test/ErrorHandler/Factory/ErrorHandlerManagerFactoryTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace AcelayaTest\ExpressiveErrorHandler\ErrorHandler\Factory;
35

46
use Acelaya\ExpressiveErrorHandler\ErrorHandler\ErrorResponseGeneratorManager;

test/Log/BasicLogMessageBuilderTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
<?php
2+
declare(strict_types=1);
3+
24
namespace AcelayaTest\ExpressiveErrorHandler\Log;
35

46
use Acelaya\ExpressiveErrorHandler\Log\BasicLogMessageBuilder;
@@ -32,7 +34,7 @@ public function onlyBaseIsProvidedWithNoError()
3234
*/
3335
public function errorIsIncludedWhenProvided()
3436
{
35-
$err = 'A super critical error';
37+
$err = new \Exception('A super critical error');
3638
$message = $this->messageBuilder->buildMessage(ServerRequestFactory::fromGlobals(), new Response(), $err);
3739
$this->assertEquals('Error occurred while dispatching request: ' . PHP_EOL . $err, $message);
3840
}

0 commit comments

Comments
 (0)