Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP 8 support #11

Merged
merged 11 commits into from
Jan 24, 2021
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/.phpcs-cache
/.phpunit.result.cache
/clover.xml
/composer.lock
/coveralls-upload.json
Expand Down
16 changes: 8 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,24 @@ env:
matrix:
fast_finish: true
include:
- php: 7.1
- php: 7.3
env:
- DEPS=lowest
- php: 7.1
- php: 7.3
env:
- DEPS=latest
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 7.2
- php: 7.4
env:
- DEPS=lowest
- php: 7.2
- php: 7.4
env:
- DEPS=latest
- php: 7.3
- CS_CHECK=true
- TEST_COVERAGE=true
- php: 8.0
env:
- DEPS=lowest
- php: 7.3
- php: 8.0
env:
- DEPS=latest

Expand Down
13 changes: 4 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,24 @@
"sort-packages": true
},
"extra": {
"branch-alias": {
"dev-master": "1.1.x-dev",
"dev-develop": "1.2.x-dev"
},
"laminas": {
"config-provider": "Mezzio\\ProblemDetails\\ConfigProvider"
}
},
"require": {
"php": "^7.1",
"php": "^7.3 || ~8.0.0",
"ext-json": "*",
"fig/http-message-util": "^1.1.2",
"laminas/laminas-zendframework-bridge": "^1.0",
"psr/container": "^1.0",
"psr/http-message": "^1.0",
"psr/http-server-middleware": "^1.0",
"spatie/array-to-xml": "^2.3",
"willdurand/negotiation": "^2.3"
"willdurand/negotiation": "^3.0"
},
"require-dev": {
"laminas/laminas-coding-standard": "~1.0.0",
"phpspec/prophecy": "^1.8.0",
"phpunit/phpunit": "^7.0.1"
"laminas/laminas-coding-standard": "~2.1.0",
"phpunit/phpunit": "^9.3"
},
"autoload": {
"psr-4": {
Expand Down
16 changes: 14 additions & 2 deletions phpcs.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
<?xml version="1.0"?>
<ruleset name="Laminas Coding Standard">
<rule ref="./vendor/laminas/laminas-coding-standard/ruleset.xml"/>
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/squizlabs/php_codesniffer/phpcs.xsd">

<arg name="basepath" value="."/>
<arg name="cache" value=".phpcs-cache"/>
<arg name="colors"/>
<arg name="extensions" value="php"/>
<arg name="parallel" value="80"/>

<!-- Show progress -->
<arg value="p"/>

<!-- Paths to check -->
<file>src</file>
<file>test</file>

<!-- Include all rules from the Laminas Coding Standard -->
<rule ref="LaminasCodingStandard"/>
</ruleset>
26 changes: 11 additions & 15 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd"
bootstrap="vendor/autoload.php"
colors="true">
<testsuites>
<testsuite name="mezzio-problem-details">
<directory>./test</directory>
</testsuite>
</testsuites>

<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="vendor/autoload.php" colors="true">
<coverage processUncoveredFiles="true">
<include>
<directory suffix=".php">./src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="mezzio-problem-details">
<directory>./test</directory>
</testsuite>
</testsuites>
</phpunit>
20 changes: 12 additions & 8 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@

namespace Mezzio\ProblemDetails;

use Zend\ProblemDetails\ProblemDetailsMiddleware as LegacyProblemDetailsMiddleware;
use Zend\ProblemDetails\ProblemDetailsNotFoundHandler as LegacyProblemDetailsNotFoundHandler;
use Zend\ProblemDetails\ProblemDetailsResponseFactory as LegacyProblemDetailsResponseFactory;

/**
* Configuration provider for the package.
*
Expand All @@ -20,7 +24,7 @@ class ConfigProvider
/**
* Returns the configuration array.
*/
public function __invoke() : array
public function __invoke(): array
{
return [
'dependencies' => $this->getDependencies(),
Expand All @@ -30,17 +34,17 @@ public function __invoke() : array
/**
* Returns the container dependencies.
*/
public function getDependencies() : array
public function getDependencies(): array
{
return [
// Legacy Zend Framework aliases
'aliases' => [
\Zend\ProblemDetails\ProblemDetailsMiddleware::class => ProblemDetailsMiddleware::class,
\Zend\ProblemDetails\ProblemDetailsNotFoundHandler::class => ProblemDetailsNotFoundHandler::class,
\Zend\ProblemDetails\ProblemDetailsResponseFactory::class => ProblemDetailsResponseFactory::class,
'aliases' => [
LegacyProblemDetailsMiddleware::class => ProblemDetailsMiddleware::class,
LegacyProblemDetailsNotFoundHandler::class => ProblemDetailsNotFoundHandler::class,
LegacyProblemDetailsResponseFactory::class => ProblemDetailsResponseFactory::class,
],
'factories' => [
ProblemDetailsMiddleware::class => ProblemDetailsMiddlewareFactory::class,
'factories' => [
ProblemDetailsMiddleware::class => ProblemDetailsMiddlewareFactory::class,
ProblemDetailsNotFoundHandler::class => ProblemDetailsNotFoundHandlerFactory::class,
ProblemDetailsResponseFactory::class => ProblemDetailsResponseFactoryFactory::class,
],
Expand Down
32 changes: 11 additions & 21 deletions src/Exception/CommonProblemDetailsExceptionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,52 +25,42 @@
*/
trait CommonProblemDetailsExceptionTrait
{
/**
* @var int
*/
/** @var int */
private $status;

/**
* @var string
*/
/** @var string */
private $detail;

/**
* @var string
*/
/** @var string */
private $title;

/**
* @var string
*/
/** @var string */
private $type;

/**
* @var array
*/
/** @var array */
private $additional = [];

public function getStatus() : int
public function getStatus(): int
{
return $this->status;
}

public function getType() : string
public function getType(): string
{
return $this->type;
}

public function getTitle() : string
public function getTitle(): string
{
return $this->title;
}

public function getDetail() : string
public function getDetail(): string
{
return $this->detail;
}

public function getAdditionalData() : array
public function getAdditionalData(): array
{
return $this->additional;
}
Expand All @@ -81,7 +71,7 @@ public function getAdditionalData() : array
* Likely useful for the JsonSerializable implementation, but also
* for cases where the XML variant is desired.
*/
public function toArray() : array
public function toArray(): array
{
$problem = [
'status' => $this->status,
Expand Down
12 changes: 6 additions & 6 deletions src/Exception/ProblemDetailsExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
*/
interface ProblemDetailsExceptionInterface extends JsonSerializable, Throwable
{
public function getStatus() : int;
public function getStatus(): int;

public function getType() : string;
public function getType(): string;

public function getTitle() : string;
public function getTitle(): string;

public function getDetail() : string;
public function getDetail(): string;

public function getAdditionalData() : array;
public function getAdditionalData(): array;

/**
* Serialize the exception to an array of problem details.
*
* Likely useful for the JsonSerializable implementation, but also
* for cases where the XML variant is desired.
*/
public function toArray() : array;
public function toArray(): array;
}
21 changes: 8 additions & 13 deletions src/ProblemDetailsMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,10 @@
*/
class ProblemDetailsMiddleware implements MiddlewareInterface
{
/**
* @var callable[]
*/
/** @var callable[] */
private $listeners = [];

/**
* @var ProblemDetailsResponseFactory
*/
/** @var ProblemDetailsResponseFactory */
private $responseFactory;

public function __construct(ProblemDetailsResponseFactory $responseFactory)
Expand All @@ -48,7 +44,7 @@ public function __construct(ProblemDetailsResponseFactory $responseFactory)
/**
* {@inheritDoc}
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// If we cannot provide a representation, act as a no-op.
if (! $this->canActAsErrorHandler($request)) {
Expand Down Expand Up @@ -81,7 +77,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
* listeners are ignored; use listeners for reporting purposes
* only.
*/
public function attachListener(callable $listener) : void
public function attachListener(callable $listener): void
{
if (in_array($listener, $this->listeners, true)) {
return;
Expand All @@ -95,7 +91,7 @@ public function attachListener(callable $listener) : void
*
* Returns a boolean false if negotiation fails.
*/
private function canActAsErrorHandler(ServerRequestInterface $request) : bool
private function canActAsErrorHandler(ServerRequestInterface $request): bool
{
$accept = $request->getHeaderLine('Accept') ?: '*/*';

Expand All @@ -108,17 +104,16 @@ private function canActAsErrorHandler(ServerRequestInterface $request) : bool
*
* Only raises exceptions for errors that are within the error_reporting mask.
*/
private function createErrorHandler() : callable
private function createErrorHandler(): callable
{
/**
* @param int $errno
* @param string $errstr
* @param string $errfile
* @param int $errline
* @return void
* @throws ErrorException if error is not within the error_reporting mask.
*/
return function (int $errno, string $errstr, string $errfile, int $errline) : void {
return function (int $errno, string $errstr, string $errfile, int $errline): void {
if (! (error_reporting() & $errno)) {
// error_reporting does not include this error
return;
Expand All @@ -135,7 +130,7 @@ private function triggerListeners(
Throwable $error,
ServerRequestInterface $request,
ResponseInterface $response
) : void {
): void {
array_walk($this->listeners, function ($listener) use ($error, $request, $response) {
$listener($error, $request, $response);
});
Expand Down
2 changes: 1 addition & 1 deletion src/ProblemDetailsMiddlewareFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ProblemDetailsMiddlewareFactory
{
public function __invoke(ContainerInterface $container) : ProblemDetailsMiddleware
public function __invoke(ContainerInterface $container): ProblemDetailsMiddleware
{
return new ProblemDetailsMiddleware($container->get(ProblemDetailsResponseFactory::class));
}
Expand Down
8 changes: 3 additions & 5 deletions src/ProblemDetailsNotFoundHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@

class ProblemDetailsNotFoundHandler implements MiddlewareInterface
{
/**
* @var ProblemDetailsResponseFactory
*/
/** @var ProblemDetailsResponseFactory */
private $responseFactory;

/**
Expand All @@ -37,7 +35,7 @@ public function __construct(ProblemDetailsResponseFactory $responseFactory)
/**
* Creates and returns a 404 response.
*/
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
// If we cannot provide a representation, act as a no-op.
if (! $this->canActAsErrorHandler($request)) {
Expand All @@ -54,7 +52,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
/**
* Can the middleware act as an error handler?
*/
private function canActAsErrorHandler(ServerRequestInterface $request) : bool
private function canActAsErrorHandler(ServerRequestInterface $request): bool
{
$accept = $request->getHeaderLine('Accept') ?: '*/*';

Expand Down
2 changes: 1 addition & 1 deletion src/ProblemDetailsNotFoundHandlerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class ProblemDetailsNotFoundHandlerFactory
{
public function __invoke(ContainerInterface $container) : ProblemDetailsNotFoundHandler
public function __invoke(ContainerInterface $container): ProblemDetailsNotFoundHandler
{
return new ProblemDetailsNotFoundHandler($container->get(ProblemDetailsResponseFactory::class));
}
Expand Down
Loading