diff --git a/.scrutinizer.yml b/.scrutinizer.yml index d754df6..a01d1bd 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -6,7 +6,7 @@ build: rabbitmq: false mongodb: false php: - version: 7.3 + version: 7.4 cache: disabled: false diff --git a/.travis.yml b/.travis.yml index cf7f671..efc25fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ sudo: false language: php php: - - 7.3 - - 7.4snapshot + - 7.4 - nightly cache: @@ -22,7 +21,6 @@ script: jobs: allow_failures: - - php: 7.4snapshot - php: nightly include: diff --git a/composer.json b/composer.json index 1162b97..a34efe4 100644 --- a/composer.json +++ b/composer.json @@ -11,24 +11,25 @@ ], "keywords": ["PSR-15", "RFC-7807", "error handling"], "require": { - "php": "^7.3", - "ext-json": "^1.7", + "php": "^7.4 || ^8.0", + "ext-json": "*", "fig/http-message-util": "^1.1", - "lcobucci/content-negotiation-middleware": "^2.0", + "lcobucci/content-negotiation-middleware": "^2.2", "psr/http-factory": "^1.0", "psr/http-server-middleware": "^1.0", "psr/log": "^1.1" }, "require-dev": { - "infection/infection": "^0.13", - "lcobucci/coding-standard": "^3.0", - "phpstan/phpstan": "^0.11", - "phpstan/phpstan-deprecation-rules": "^0.11", - "phpstan/phpstan-phpunit": "^0.11", - "phpstan/phpstan-strict-rules": "^0.11", - "phpunit/phpunit": "^8.2", - "squizlabs/php_codesniffer": "^3.4", - "zendframework/zend-diactoros": "^2.0" + "infection/infection": "^0.15", + "laminas/laminas-diactoros": "^2.2", + "lcobucci/coding-standard": "^4.0", + "phpstan/extension-installer": "^1.0", + "phpstan/phpstan": "^0.12", + "phpstan/phpstan-deprecation-rules": "^0.12", + "phpstan/phpstan-phpunit": "^0.12", + "phpstan/phpstan-strict-rules": "^0.12", + "phpunit/phpunit": "^9.0", + "squizlabs/php_codesniffer": "^3.5" }, "autoload": { "psr-4": { diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 46705ff..7c87780 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,9 +1,3 @@ -includes: - - vendor/phpstan/phpstan-phpunit/extension.neon - - vendor/phpstan/phpstan-phpunit/rules.neon - - vendor/phpstan/phpstan-deprecation-rules/rules.neon - - vendor/phpstan/phpstan-strict-rules/rules.neon - parameters: level: 7 paths: diff --git a/src/DebugInfoStrategy/NoTrace.php b/src/DebugInfoStrategy/NoTrace.php index ebf464c..09dab90 100644 --- a/src/DebugInfoStrategy/NoTrace.php +++ b/src/DebugInfoStrategy/NoTrace.php @@ -26,6 +26,9 @@ public function extractDebugInfo(Throwable $error): ?array return $debugInfo; } + /** + * @return Generator> + */ private function streamStack(?Throwable $previous): Generator { if ($previous === null) { diff --git a/src/ErrorConversionMiddleware.php b/src/ErrorConversionMiddleware.php index 461416e..78af67e 100644 --- a/src/ErrorConversionMiddleware.php +++ b/src/ErrorConversionMiddleware.php @@ -24,20 +24,9 @@ final class ErrorConversionMiddleware implements MiddlewareInterface private const STATUS_URL = 'https://httpstatuses.com/'; - /** - * @var ResponseFactoryInterface - */ - private $responseFactory; - - /** - * @var DebugInfoStrategy - */ - private $debugInfoStrategy; - - /** - * @var StatusCodeExtractionStrategy - */ - private $statusCodeExtractor; + private ResponseFactoryInterface $responseFactory; + private DebugInfoStrategy $debugInfoStrategy; + private StatusCodeExtractionStrategy $statusCodeExtractor; public function __construct( ResponseFactoryInterface $responseFactory, diff --git a/src/ErrorLoggingMiddleware.php b/src/ErrorLoggingMiddleware.php index c710794..1c9002f 100644 --- a/src/ErrorLoggingMiddleware.php +++ b/src/ErrorLoggingMiddleware.php @@ -12,10 +12,7 @@ final class ErrorLoggingMiddleware implements MiddlewareInterface { - /** - * @var LoggerInterface - */ - private $logger; + private LoggerInterface $logger; public function __construct(LoggerInterface $logger) { diff --git a/src/StatusCodeExtractionStrategy/ClassMap.php b/src/StatusCodeExtractionStrategy/ClassMap.php index b750fa6..a5108d7 100644 --- a/src/StatusCodeExtractionStrategy/ClassMap.php +++ b/src/StatusCodeExtractionStrategy/ClassMap.php @@ -24,7 +24,7 @@ final class ClassMap implements StatusCodeExtractionStrategy /** * @var array */ - private $conversionMap; + private array $conversionMap; /** * @param array $conversionMap @@ -42,6 +42,8 @@ public function extractStatusCode(Throwable $error): int } } - return $error->getCode() ?: StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR; + $code = $error->getCode(); + + return $code !== 0 ? $code : StatusCodeInterface::STATUS_INTERNAL_SERVER_ERROR; } } diff --git a/tests/ErrorConversionMiddlewareTest.php b/tests/ErrorConversionMiddlewareTest.php index 0ebf151..d0ca5bf 100644 --- a/tests/ErrorConversionMiddlewareTest.php +++ b/tests/ErrorConversionMiddlewareTest.php @@ -4,6 +4,9 @@ namespace Lcobucci\ErrorHandling\Tests; use Fig\Http\Message\StatusCodeInterface; +use Laminas\Diactoros\Response; +use Laminas\Diactoros\ResponseFactory; +use Laminas\Diactoros\ServerRequest; use Lcobucci\ContentNegotiation\UnformattedResponse; use Lcobucci\ErrorHandling\DebugInfoStrategy; use Lcobucci\ErrorHandling\DebugInfoStrategy\NoDebugInfo; @@ -16,9 +19,6 @@ use Psr\Http\Server\RequestHandlerInterface; use RuntimeException; use Throwable; -use Zend\Diactoros\Response; -use Zend\Diactoros\ResponseFactory; -use Zend\Diactoros\ServerRequest; /** * @coversDefaultClass \Lcobucci\ErrorHandling\ErrorConversionMiddleware @@ -29,15 +29,8 @@ */ final class ErrorConversionMiddlewareTest extends TestCase { - /** - * @var ResponseFactory - */ - private $responseFactory; - - /** - * @var ClassMap - */ - private $statusCodeExtractor; + private ResponseFactory $responseFactory; + private ClassMap $statusCodeExtractor; /** * @before @@ -94,7 +87,7 @@ public function processShouldConvertTheExceptionIntoAnUnformattedResponseWithThe } /** - * @return array>> + * @return array>> */ public function possibleConversions(): iterable { diff --git a/tests/ErrorLoggingMiddlewareTest.php b/tests/ErrorLoggingMiddlewareTest.php index 0a189f3..febd446 100644 --- a/tests/ErrorLoggingMiddlewareTest.php +++ b/tests/ErrorLoggingMiddlewareTest.php @@ -3,14 +3,14 @@ namespace Lcobucci\ErrorHandling\Tests; +use Laminas\Diactoros\Response; +use Laminas\Diactoros\ServerRequest; use Lcobucci\ErrorHandling\ErrorLoggingMiddleware; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Http\Server\RequestHandlerInterface; use Psr\Log\LoggerInterface; use RuntimeException; -use Zend\Diactoros\Response; -use Zend\Diactoros\ServerRequest; /** * @coversDefaultClass \Lcobucci\ErrorHandling\ErrorLoggingMiddleware @@ -20,7 +20,7 @@ final class ErrorLoggingMiddlewareTest extends TestCase /** * @var LoggerInterface&MockObject */ - private $logger; + private LoggerInterface $logger; /** * @before