NotFoundHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A handle() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Web;
6
7
use Psr\Http\Message\ResponseFactoryInterface;
8
use Psr\Http\Message\ResponseInterface;
9
use Psr\Http\Message\ServerRequestInterface;
10
use Psr\Http\Server\RequestHandlerInterface;
11
use Yiisoft\Http\Status;
12
13
final class NotFoundHandler implements RequestHandlerInterface
14
{
15
    /**
16
     * @var ResponseFactoryInterface
17
     */
18
    private ResponseFactoryInterface $responseFactory;
19
20
    /**
21
     * NotFoundHandler constructor.
22
     *
23
     * @param ResponseFactoryInterface $responseFactory
24
     */
25 10
    public function __construct(ResponseFactoryInterface $responseFactory)
26
    {
27 10
        $this->responseFactory = $responseFactory;
28 10
    }
29
30
    /**
31
     * Handles a request and produces a response.
32
     *
33
     * May call other collaborating code to generate the response.
34
     */
35 2
    public function handle(ServerRequestInterface $request): ResponseInterface
36
    {
37 2
        $path = $request->getUri()->getPath();
38 2
        $response = $this->responseFactory->createResponse(Status::NOT_FOUND);
39 2
        $response->getBody()->write("We were unable to find the page $path.");
40 2
        return $response;
41
    }
42
}
43