Completed
Push — master ( b7f6a5...e297c9 )
by Dawid
05:58
created

NotFoundMiddleware   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 5
cts 5
cp 1
rs 10
c 0
b 0
f 0
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 9 2
1
<?php declare(strict_types=1);
2
3
namespace Igni\Http\Middleware;
4
5
use Igni\Http\Exception\NotFoundException;
6
use Igni\Http\Response;
7
use Psr\Http\Message\ResponseInterface;
8
use Psr\Http\Message\ServerRequestInterface;
9
use Psr\Http\Server\MiddlewareInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
12
/**
13
 * Middleware for generating default response in case application cannot find route definition for client's request.
14
 *
15
 * @package Igni\Http\Middleware
16
 */
17
final class NotFoundMiddleware implements MiddlewareInterface
18
{
19
    /**
20
     * @see MiddlewareInterface::process
21
     *
22
     * @param ServerRequestInterface $request
23
     * @param RequestHandlerInterface $next
24
     * @return ResponseInterface
25
     */
26 1
    public function process(ServerRequestInterface $request, RequestHandlerInterface $next): ResponseInterface
27
    {
28
        try {
29 1
            $response = $next->handle($request);
30 1
        } catch (NotFoundException $exception) {
31 1
            $response = Response::fromText('Not Found', Response::HTTP_NOT_FOUND);
32
        }
33
34 1
        return $response;
35
    }
36
}
37