HttpExceptionMiddleware::process()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.0488

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 8
c 1
b 0
f 0
nc 4
nop 2
dl 0
loc 15
ccs 7
cts 8
cp 0.875
crap 5.0488
rs 9.6111
1
<?php
2
declare(strict_types=1);
3
4
namespace Ctw\Middleware\HttpExceptionMiddleware;
5
6
use Ctw\Http\HttpException;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\RequestHandlerInterface;
10
use Throwable;
11
12
class HttpExceptionMiddleware extends AbstractHttpExceptionMiddleware
13
{
14 4
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
15
    {
16
        try {
17 4
            return $handler->handle($request);
18 4
        } catch (Throwable $throwable) {
19
            // continue;
20
        }
21
22 4
        if (!$this->isDevelopmentMode() && $throwable instanceof HttpException\HttpExceptionInterface) {
23 4
            return $this->asJson($request)
24 2
                ? $this->getJsonResponse($throwable)
25 4
                : $this->getHtmlResponse($throwable);
26
        }
27
28
        throw $throwable;
29
    }
30
}
31