Fix PHPStan issues
This commit is contained in:
parent
5522936e20
commit
7c6e95a42f
|
@ -31,6 +31,8 @@ use Psr\Http\Server\MiddlewareInterface;
|
|||
*
|
||||
* @author Sebastian Meyer <sebastian.meyer@opencultureconsulting.com>
|
||||
* @package opencultureconsulting/psr15
|
||||
*
|
||||
* @extends StrictQueue<MiddlewareInterface>
|
||||
*/
|
||||
class MiddlewareQueue extends StrictQueue
|
||||
{
|
||||
|
@ -42,7 +44,7 @@ class MiddlewareQueue extends StrictQueue
|
|||
*
|
||||
* @param iterable<MiddlewareInterface> $middlewares Initial set of PSR-15 middlewares
|
||||
*/
|
||||
public function __construct(mixed ...$middlewares)
|
||||
public function __construct(iterable $middlewares = [])
|
||||
{
|
||||
parent::__construct($middlewares, [MiddlewareInterface::class]);
|
||||
}
|
||||
|
|
|
@ -68,25 +68,14 @@ class QueueRequestHandler implements RequestHandlerInterface
|
|||
public function handle(?ServerRequestInterface $request = null): ResponseInterface
|
||||
{
|
||||
$this->request = $request ?? $this->request;
|
||||
if (count($this->queue) > 0) {
|
||||
$middleware = $this->queue->dequeue();
|
||||
// It is RECOMMENDED that any application using middleware includes a
|
||||
// component that catches exceptions and converts them into responses.
|
||||
// This middleware SHOULD be the first component executed and wrap all
|
||||
// further processing to ensure that a response is always generated.
|
||||
try {
|
||||
if (count($this->queue) > 0) {
|
||||
$middleware = $this->queue->dequeue();
|
||||
if (!is_object($middleware) || !is_a($middleware, MiddlewareInterface::class)) {
|
||||
throw new DomainException(
|
||||
sprintf(
|
||||
'Middleware must be of type %s, %s given.',
|
||||
MiddlewareInterface::class,
|
||||
get_debug_type($middleware)
|
||||
),
|
||||
500
|
||||
);
|
||||
}
|
||||
$this->response = $middleware->process($this->request, $this);
|
||||
}
|
||||
} catch(Exception $exception) {
|
||||
$options = [
|
||||
'options' => [
|
||||
|
@ -96,9 +85,18 @@ class QueueRequestHandler implements RequestHandlerInterface
|
|||
]
|
||||
];
|
||||
$statusCode = filter_var($exception->getCode(), FILTER_VALIDATE_INT, $options);
|
||||
$this->response = new Response($statusCode, [], $exception->getMessage());
|
||||
$this->response = new Response(
|
||||
$statusCode,
|
||||
[],
|
||||
sprintf(
|
||||
'Exception thrown in middleware %s: %s',
|
||||
get_debug_type($middleware),
|
||||
$exception->getMessage()
|
||||
)
|
||||
);
|
||||
$this->respond(1);
|
||||
}
|
||||
}
|
||||
return $this->response;
|
||||
}
|
||||
|
||||
|
@ -168,7 +166,7 @@ class QueueRequestHandler implements RequestHandlerInterface
|
|||
*
|
||||
* @param iterable<MiddlewareInterface> $middlewares Initial set of middlewares
|
||||
*/
|
||||
public function __construct(?iterable $middlewares = [])
|
||||
public function __construct(iterable $middlewares = [])
|
||||
{
|
||||
$this->request = ServerRequest::fromGlobals();
|
||||
$this->queue = MiddlewareQueue::getInstance($middlewares);
|
||||
|
|
Loading…
Reference in New Issue