ErrorHandlerMiddleware   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 4
c 1
b 0
f 0
dl 0
loc 21
ccs 4
cts 4
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A process() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace HttpSoft\ErrorHandler;
6
7
use ErrorException;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\MiddlewareInterface;
11
use Psr\Http\Server\RequestHandlerInterface;
12
13
final class ErrorHandlerMiddleware implements MiddlewareInterface
14
{
15
    use ErrorHandlerTrait;
16
17
    /**
18
     * @param ErrorResponseGeneratorInterface|null $responseGenerator
19
     */
20 13
    public function __construct(?ErrorResponseGeneratorInterface $responseGenerator = null)
21
    {
22 13
        $this->responseGenerator = $responseGenerator ?? new ErrorResponseGenerator();
23
    }
24
25
    /**
26
     * @param ServerRequestInterface $request
27
     * @param RequestHandlerInterface $handler
28
     * @return ResponseInterface
29
     * @throws ErrorException
30
     */
31 13
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
32
    {
33 13
        return $this->handleError($request, $handler);
34
    }
35
}
36