diff --git a/.gitattributes b/.gitattributes
index c540470..b67c7ca 100644
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,10 +1,10 @@
* text=auto eol=lf
-/tests export-ignore
-.editorconfig export-ignore
-.gitattributes export-ignore
-.gitignore export-ignore
-.php_cs export-ignore
-.travis.yml export-ignore
-phpcs.xml.dist export-ignore
-phpunit.xml.dist export-ignore
+/tests export-ignore
+.editorconfig export-ignore
+.gitattributes export-ignore
+.gitignore export-ignore
+.php-cs-fixer.php export-ignore
+phpcs.xml.dist export-ignore
+phpunit.xml.dist export-ignore
+.phpstan.neon export-ignore
diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml
index 327717c..5d14a59 100644
--- a/.github/workflows/main.yaml
+++ b/.github/workflows/main.yaml
@@ -1,10 +1,10 @@
name: "testing"
on:
- push:
- branches: [ master ]
- pull_request:
- branches: [ master ]
+ push:
+ branches: [ master ]
+ pull_request:
+ branches: [ master ]
jobs:
qa:
@@ -13,19 +13,19 @@ jobs:
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v4
- name: Validate composer.json and composer.lock
run: composer validate
- name: Cache Composer packages
id: composer-cache
- uses: actions/cache@v2
+ uses: actions/cache@v4
with:
- path: vendor
- key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
- restore-keys: |
- ${{ runner.os }}-php-
+ path: vendor
+ key: ${{ runner.os }}-php-${{ hashFiles('**/composer.lock') }}
+ restore-keys: |
+ ${{ runner.os }}-php-
- name: Install dependencies
if: steps.composer-cache.outputs.cache-hit != 'true'
@@ -40,19 +40,19 @@ jobs:
strategy:
matrix:
- php:
- - 7.2
- - 7.3
- - 7.4
- composer-args: [ "" ]
- include:
- - php: 8.0
- composer-args: --ignore-platform-reqs
- fail-fast: false
+ php:
+ - 7.2
+ - 7.3
+ - 7.4
+ - 8.0
+ - 8.1
+ - 8.2
+ - 8.3
+ - 8.4
steps:
- name: Checkout
- uses: actions/checkout@v2
+ uses: actions/checkout@v4
- name: Install PHP
uses: shivammathur/setup-php@v2
@@ -60,17 +60,14 @@ jobs:
php-version: ${{ matrix.php }}
- name: Cache PHP dependencies
- uses: actions/cache@v2
+ uses: actions/cache@v4
with:
path: vendor
key: ${{ runner.os }}-php-${{ matrix.php }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-php-${{ matrix.php }}-composer-
- name: Install dependencies
- run: composer install --prefer-dist --no-progress ${{ matrix.composer-args }}
+ run: composer install --prefer-dist --no-progress
- name: Tests
run: composer test
-
- - name: Tests coverage
- run: composer coverage
diff --git a/.gitignore b/.gitignore
index 364d1a4..5ae8693 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,3 +2,5 @@ vendor
composer.lock
coverage
*.cache
+.idea
+kit
diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php
new file mode 100644
index 0000000..90b12a3
--- /dev/null
+++ b/.php-cs-fixer.php
@@ -0,0 +1,10 @@
+setFinder(
+ PhpCsFixer\Finder::create()
+ ->files()
+ ->name('*.php')
+ ->in(__DIR__.'/src')
+ ->in(__DIR__.'/tests')
+ );
\ No newline at end of file
diff --git a/.phpstan.neon b/.phpstan.neon
new file mode 100644
index 0000000..9045762
--- /dev/null
+++ b/.phpstan.neon
@@ -0,0 +1,6 @@
+parameters:
+ level: 8
+ paths:
+ - src
+ - tests
+ inferPrivatePropertyTypeFromConstructor: true
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 108b762..7e51947 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).
+## [1.1.0] - 2025-03-21
+### Added
+- Support for PHP 8.4
+
## [1.0.2] - 2020-12-03
### Added
- Support for PHP 8.0
@@ -16,5 +20,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
## 1.0.0 - 2019-12-01
First version
+[1.1.0]: https://github.com/middlewares/error-response/compare/v1.0.2...v1.1.0
[1.0.2]: https://github.com/middlewares/error-response/compare/v1.0.1...v1.0.2
[1.0.1]: https://github.com/middlewares/error-response/compare/v1.0.0...v1.0.1
diff --git a/LICENSE b/LICENSE
index 017c0cd..374fb13 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,6 +1,6 @@
The MIT License (MIT)
-Copyright (c) 2019
+Copyright (c) 2019-2025
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
diff --git a/composer.json b/composer.json
index b8003fb..d97a8b2 100644
--- a/composer.json
+++ b/composer.json
@@ -16,16 +16,16 @@
},
"require": {
"php": "^7.2 || ^8.0",
- "psr/http-server-middleware": "^1.0"
+ "psr/http-server-middleware": "^1"
},
"require-dev": {
- "middlewares/utils": "^3.0",
- "phpunit/phpunit": "^8|^9",
- "friendsofphp/php-cs-fixer": "^2.0",
- "squizlabs/php_codesniffer": "^3.0",
- "oscarotero/php-cs-fixer-config": "^1.0",
- "phpstan/phpstan": "^0.12",
- "laminas/laminas-diactoros": "^2.3"
+ "middlewares/utils": "^2 || ^3 || ^4",
+ "phpunit/phpunit": "^8 || ^9",
+ "friendsofphp/php-cs-fixer": "^3",
+ "squizlabs/php_codesniffer": "^3",
+ "oscarotero/php-cs-fixer-config": "^2",
+ "phpstan/phpstan": "^1 || ^2",
+ "laminas/laminas-diactoros": "^2 || ^3"
},
"autoload": {
"psr-4": {
@@ -45,4 +45,4 @@
"coverage": "phpunit --coverage-text",
"coverage-html": "phpunit --coverage-html=coverage"
}
-}
+}
\ No newline at end of file
diff --git a/phpcs.xml b/phpcs.xml
new file mode 100644
index 0000000..7814331
--- /dev/null
+++ b/phpcs.xml
@@ -0,0 +1,16 @@
+
+
+ Middlewares coding standard
+
+
+
+
+
+
+
+
+
+
+ src
+ tests
+
diff --git a/phpunit.xml b/phpunit.xml
new file mode 100644
index 0000000..f4bf390
--- /dev/null
+++ b/phpunit.xml
@@ -0,0 +1,33 @@
+
+
+
+
+ tests
+
+
+
+
+
+ ./src
+
+ ./tests
+ ./vendor
+
+
+
+
diff --git a/src/ErrorResponder/AbstractResponder.php b/src/ErrorResponder/AbstractResponder.php
index 371d788..af50fff 100644
--- a/src/ErrorResponder/AbstractResponder.php
+++ b/src/ErrorResponder/AbstractResponder.php
@@ -13,13 +13,21 @@ abstract class AbstractResponder implements ResponderInterface
/** @var StreamFactoryInterface */
protected $streamFactory;
+ /** @var string[] */
protected $statusCodes = ['/^(4|5)\d\d/'];
+
+ /** @var string[] */
protected $contentTypes = [];
+ /**
+ * @param StreamFactoryInterface|null $streamFactory
+ * @param string[]|null $statusCodes
+ * @param string[]|null $contentTypes
+ */
public function __construct(
- StreamFactoryInterface $streamFactory = null,
- array $statusCodes = null,
- array $contentTypes = null
+ ?StreamFactoryInterface $streamFactory = null,
+ ?array $statusCodes = null,
+ ?array $contentTypes = null
) {
$this->streamFactory = $streamFactory ?? Factory::getStreamFactory();
diff --git a/src/ErrorResponder/HtmlResponder.php b/src/ErrorResponder/HtmlResponder.php
index 821eb9d..1e1592f 100644
--- a/src/ErrorResponder/HtmlResponder.php
+++ b/src/ErrorResponder/HtmlResponder.php
@@ -5,6 +5,7 @@
class HtmlResponder extends AbstractResponder
{
+ /** @var string[] */
protected $contentTypes = ['text/html'];
public function getBodyContent(int $code, string $message): string
diff --git a/src/ErrorResponder/JsonResponder.php b/src/ErrorResponder/JsonResponder.php
index b435eb3..31baba0 100644
--- a/src/ErrorResponder/JsonResponder.php
+++ b/src/ErrorResponder/JsonResponder.php
@@ -5,6 +5,7 @@
class JsonResponder extends AbstractResponder
{
+ /** @var string[] */
protected $contentTypes = ['application/json'];
public function getBodyContent(int $code, string $message): string
diff --git a/src/ErrorResponse.php b/src/ErrorResponse.php
index b01efb3..edd3bc7 100644
--- a/src/ErrorResponse.php
+++ b/src/ErrorResponse.php
@@ -3,6 +3,9 @@
namespace Middlewares;
+use Middlewares\ErrorResponder\HtmlResponder;
+use Middlewares\ErrorResponder\JsonResponder;
+use Middlewares\ErrorResponder\ResponderInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
@@ -10,17 +13,18 @@
class ErrorResponse implements MiddlewareInterface
{
+ /** @var ResponderInterface[] */
+ private $responders;
+
/**
- * @var ErrorResponder\ResponderInterface[]
+ * @param ResponderInterface[]|null $responders
*/
- private $responders = [];
-
- public function __construct(array $responders = null)
+ public function __construct(?array $responders = null)
{
if ($responders === null) {
$responders = [
- new ErrorResponder\HtmlResponder(),
- new ErrorResponder\JsonResponder(),
+ new HtmlResponder(),
+ new JsonResponder(),
];
}
diff --git a/tests/ErrorResponseTest.php b/tests/ErrorResponseTest.php
index fa541a7..8e609c0 100644
--- a/tests/ErrorResponseTest.php
+++ b/tests/ErrorResponseTest.php
@@ -1,5 +1,7 @@
assertEquals($content, (string) $response->getBody());
}
- public function testJsonErrorResponse()
+ public function testJsonErrorResponse(): void
{
$request = Factory::createServerRequest('GET', '/');