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

Feature/dev dependencies #17

Merged
merged 3 commits into from
Feb 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
/.travis.yml export-ignore
/phpcs.xml export-ignore
/phpunit.xml.dist export-ignore
/phpstan.neon export-ignore
/docker-compose.yml export-ignore
/docker-compose.override.yml.dist export-ignore
/indocker export-ignore
/composer.lock export-ignore
/infection.json export-ignore
/CHANGELOG.md export-ignore
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@
vendor
composer.lock
build
docker-compose.override.yml
.phpunit.result.cache
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ install:

script:
- mkdir build
- if [[ $DEPS == 'latest' ]]; then composer ac:ci ; fi
- if [[ $DEPS == 'lowest' ]]; then composer ac:test ; fi
- if [[ $DEPS == 'latest' ]]; then composer ci ; fi
- if [[ $DEPS == 'lowest' ]]; then composer test ; fi

after_success:
- if [[ $DEPS == 'latest' ]]; then wget https://scrutinizer-ci.com/ocular.phar ; fi
Expand Down
26 changes: 26 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,31 @@
# CHANGELOG

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org).

## [Unreleased]

#### Added

* [#14](https://github.com/acelaya/ze-content-based-error-handler/issues/14) Added PHP 7.3 to build matrix

#### Changed

* [#16](https://github.com/acelaya/ze-content-based-error-handler/issues/16) Added compatibility with expressive 3

#### Deprecated

* *Nothing*

#### Removed

* *Nothing*

#### Fixed

* *Nothing*


## 2.2.0 - 2018-03-25

Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
[![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)
[![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)
[![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)
[![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)
[![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)
[![License](https://poser.pugx.org/acelaya/ze-content-based-error-handler/license?format=flat-square)](LICENSE)
[![Latest Stable Version](https://img.shields.io/github/release/acelaya/ze-content-based-error-handler.svg?style=flat-square)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
[![Total Downloads](https://img.shields.io/packagist/dt/acelaya/ze-content-based-error-handler.svg?style=flat-square)](https://packagist.org/packages/acelaya/ze-content-based-error-handler)
[![License](https://img.shields.io/github/license/acelaya/ze-content-based-error-handler.svg?style=flat-square)](https://github.com/acelaya/ze-content-based-error-handler/blob/master/LICENSE)
[![Paypal Donate](https://img.shields.io/badge/Donate-paypal-blue.svg?style=flat-square&logo=paypal&colorA=cccccc)](https://acel.me/donate)

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

Expand Down
37 changes: 20 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
"zendframework/zend-servicemanager": "^3.0"
},
"require-dev": {
"infection/infection": "^0.9.0",
"phpstan/phpstan": "^0.10.0",
"phpunit/phpunit": "^7.0",
"slevomat/coding-standard": "^4.1",
"squizlabs/php_codesniffer": "^3.1"
"infection/infection": "^0.12.0",
"phpstan/phpstan": "^0.11.1",
"phpunit/phpunit": "^8.0 || ^7.5",
"shlinkio/php-coding-standard": "1.0.0"
},
"license": "MIT",
"authors": [
Expand All @@ -40,20 +39,24 @@
}
},
"scripts": {
"ac:ci": [
"@ac:cs",
"@ac:stan",
"@ac:test",
"@ac:infection"
"ci": [
"@cs",
"@stan",
"@test:ci",
"@infection:ci"
],

"ac:cs": "phpcs",
"ac:cs-fix": "phpcbf",
"ac:stan": "phpstan analyse src/ --level=6",
"ac:test": "phpdbg -qrr vendor/bin/phpunit --coverage-clover build/clover.xml --colors=always",
"ac:pretty-test": "phpdbg -qrr vendor/bin/phpunit --coverage-html build/coverage",
"ac:infection": "phpdbg -qrr vendor/bin/infection --threads=4 --min-msi=90 --log-verbosity=2 --only-covered",
"ac:infection-show": "phpdbg -qrr vendor/bin/infection --threads=4 --min-msi=90 --log-verbosity=2 --only-covered --show-mutations"
"cs": "phpcs",
"cs:fix": "phpcbf",
"stan": "phpstan analyse src/ --level=6",

"test": "phpdbg -qrr vendor/bin/phpunit --colors=always",
"test:pretty": "phpdbg -qrr vendor/bin/phpunit --coverage-html build/coverage",
"test:ci": "phpdbg -qrr vendor/bin/phpunit --colors=always --coverage-clover=build/clover.xml --coverage-xml=build/coverage-xml --log-junit=build/phpunit.junit.xml",

"infection": "phpdbg -qrr vendor/bin/infection --threads=4 --min-msi=80 --log-verbosity=default --only-covered",
"infection:ci": "phpdbg -qrr vendor/bin/infection --threads=4 --min-msi=80 --log-verbosity=default --only-covered --coverage=build",
"infection:show": "phpdbg -qrr vendor/bin/infection --threads=4 --min-msi=80 --log-verbosity=default --only-covered --show-mutations"
},
"extra": {
"zf": {
Expand Down
8 changes: 8 additions & 0 deletions docker-compose.override.yml.dist
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

services:
ze_cbeh_php:
user: 1000:1000
volumes:
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
8 changes: 8 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version: '3'

services:
ze_cbeh_php:
container_name: ze_cbeh_php
image: composer:1.8.3
volumes:
- ./:/app
3 changes: 3 additions & 0 deletions indocker
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

docker-compose run ze_cbeh_php /bin/sh -c "$*"
5 changes: 3 additions & 2 deletions infection.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"src"
]
},
"timeout": 10,
"timeout": 5,
"logs": {
"text": "build/infection/infection-log.txt",
"summary": "build/infection/summary-log.txt",
Expand All @@ -15,6 +15,7 @@
},
"mutators": {
"@default": true,
"IdenticalEqual": false
"IdenticalEqual": false,
"NotIdenticalNotEqual": false
}
}
33 changes: 1 addition & 32 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,44 +1,13 @@
<?xml version="1.0"?>
<ruleset name="Coding standard">
<description>Coding standard specification</description>
<config name="installed_paths" value="../../slevomat/coding-standard"/>

<!-- display progress -->
<arg value="p"/>
<arg name="colors"/>

<!-- inherit rules from: -->
<rule ref="PSR2"/>
<rule ref="Generic.Arrays.DisallowLongArraySyntax"/>
<!-- Make sure string concatenations use 1 space between every element -->
<rule ref="Squiz.Strings.ConcatenationSpacing">
<properties>
<property name="spacing" value="1"/>
<property name="ignoreNewlines" value="true"/>
</properties>
</rule>
<rule ref="Squiz.WhiteSpace.SuperfluousWhitespace">
<properties>
<property name="ignoreBlankLines" value="false"/>
</properties>
</rule>
<rule ref="Squiz.Strings.DoubleQuoteUsage"/>
<rule ref="SlevomatCodingStandard.TypeHints.DeclareStrictTypes">
<properties>
<property name="newlinesCountBetweenOpenTagAndDeclare" value="1"/>
<property name="spacesCountAroundEqualsSign" value="0"/>
</properties>
</rule>
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<properties>
<property name="searchAnnotations" value="true"/>
</properties>
</rule>
<!-- Force strict comparison with === or !== instead of == or != -->
<rule ref="SlevomatCodingStandard.ControlStructures.DisallowEqualOperators"/>
<rule ref="SlevomatCodingStandard.Arrays.TrailingArrayComma"/>
<rule ref="SlevomatCodingStandard.Namespaces.AlphabeticallySortedUses"/>
<rule ref="SlevomatCodingStandard.TypeHints.ReturnTypeHintSpacing"/>
<rule ref="Shlinkio"/>

<!-- Paths to check -->
<file>src</file>
Expand Down
28 changes: 12 additions & 16 deletions src/ErrorHandler/ContentBasedErrorResponseGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,22 @@
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Log\LoggerInterface;
use Throwable;
use function explode;
use function implode;
use function sprintf;

class ContentBasedErrorResponseGenerator implements ErrorResponseGeneratorInterface
{
private const DEFAULT_CONTENT = 'text/html';

/**
* @var ErrorResponseGeneratorManagerInterface
*/
/** @var ErrorResponseGeneratorManagerInterface */
private $errorHandlerManager;
/**
* @var LoggerInterface
*/
/** @var LoggerInterface */
private $logger;
/**
* @var LogMessageBuilderInterface
*/
/** @var LogMessageBuilderInterface */
private $logMessageBuilder;
/**
* @var string
*/
/** @var string */
private $defaultContentType;

/**
Expand Down Expand Up @@ -58,7 +54,7 @@ public function __construct(
* @return Response
* @throws InvalidArgumentException
*/
public function __invoke(?\Throwable $e, Request $request, Response $response): Response
public function __invoke(?Throwable $e, Request $request, Response $response): Response
{
// Try to get an error handler for provided request accepted type
$errorHandler = $this->resolveErrorHandlerFromAcceptHeader($request);
Expand All @@ -78,7 +74,7 @@ private function resolveErrorHandlerFromAcceptHeader(Request $request): callable
// Try to find an error handler for one of the accepted content types
$accepts = $request->hasHeader('Accept') ? $request->getHeaderLine('Accept') : $this->defaultContentType;
/** @var array $accepts */
$accepts = \explode(',', $accepts);
$accepts = explode(',', $accepts);
foreach ($accepts as $accept) {
if (! $this->errorHandlerManager->has($accept)) {
continue;
Expand All @@ -93,10 +89,10 @@ private function resolveErrorHandlerFromAcceptHeader(Request $request): callable
}

// It wasn't possible to find an error handler
throw new InvalidArgumentException(\sprintf(
throw new InvalidArgumentException(sprintf(
'It wasn\'t possible to find an error handler for ["%s"] content types. '
. 'Make sure you have registered at least the default "%s" content type',
\implode('", "', $accepts),
implode('", "', $accepts),
$this->defaultContentType
));
}
Expand Down
3 changes: 2 additions & 1 deletion src/ErrorHandler/ErrorResponseGeneratorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Throwable;

interface ErrorResponseGeneratorInterface
{
Expand All @@ -16,5 +17,5 @@ interface ErrorResponseGeneratorInterface
* @param Response $response
* @return Response
*/
public function __invoke(?\Throwable $e, Request $request, Response $response);
public function __invoke(?Throwable $e, Request $request, Response $response);
}
11 changes: 8 additions & 3 deletions src/ErrorHandler/ErrorResponseGeneratorManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@

use Zend\ServiceManager\AbstractPluginManager;
use Zend\ServiceManager\Exception\InvalidServiceException;
use function get_class;
use function gettype;
use function is_callable;
use function is_object;
use function sprintf;

class ErrorResponseGeneratorManager extends AbstractPluginManager implements ErrorResponseGeneratorManagerInterface
{
Expand All @@ -14,14 +19,14 @@ class ErrorResponseGeneratorManager extends AbstractPluginManager implements Err
*/
public function validate($instance)
{
if (\is_callable($instance)) {
if (is_callable($instance)) {
return;
}

throw new InvalidServiceException(\sprintf(
throw new InvalidServiceException(sprintf(
'Only callables are valid plugins for "%s", but "%s" was provided',
__CLASS__,
\is_object($instance) ? \get_class($instance) : \gettype($instance)
is_object($instance) ? get_class($instance) : gettype($instance)
));
}
}
4 changes: 3 additions & 1 deletion src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Acelaya\ExpressiveErrorHandler\Exception;

interface ExceptionInterface extends \Throwable
use Throwable;

interface ExceptionInterface extends Throwable
{
}
4 changes: 3 additions & 1 deletion src/Exception/InvalidArgumentException.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

namespace Acelaya\ExpressiveErrorHandler\Exception;

class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
use InvalidArgumentException as SplInvalidArgumentException;

class InvalidArgumentException extends SplInvalidArgumentException implements ExceptionInterface
{
}
7 changes: 5 additions & 2 deletions src/Log/BasicLogMessageBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Throwable;
use const PHP_EOL;
use function sprintf;

class BasicLogMessageBuilder implements LogMessageBuilderInterface
{
Expand All @@ -16,13 +19,13 @@ class BasicLogMessageBuilder implements LogMessageBuilderInterface
* @param \Throwable|null $err
* @return string
*/
public function buildMessage(Request $request, Response $response, \Throwable $err = null): string
public function buildMessage(Request $request, Response $response, Throwable $err = null): string
{
$base = 'Error occurred while dispatching request';
if ($err === null) {
return $base;
}

return \sprintf('%s:%s%s', $base, PHP_EOL, $err);
return sprintf('%s:%s%s', $base, PHP_EOL, $err);
}
}
3 changes: 2 additions & 1 deletion src/Log/LogMessageBuilderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Throwable;

interface LogMessageBuilderInterface
{
Expand All @@ -16,5 +17,5 @@ interface LogMessageBuilderInterface
* @param \Throwable|null $err
* @return string
*/
public function buildMessage(Request $request, Response $response, \Throwable $err = null): string;
public function buildMessage(Request $request, Response $response, Throwable $err = null): string;
}
Loading