NotFoundHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 6
ccs 5
cts 5
cp 1
rs 10
cc 1
nc 1
nop 1
crap 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