NotFoundHandler::handle()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 8
nc 1
nop 1
dl 0
loc 10
ccs 9
cts 9
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Yii\Http\Handler;
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
/**
14
 * NotFoundHandler is used as a fallback handler by default {@see \Yiisoft\Yii\Http\Application}.
15
 */
16
final class NotFoundHandler implements RequestHandlerInterface
17
{
18 10
    public function __construct(private ResponseFactoryInterface $responseFactory)
19
    {
20 10
    }
21
22
    /**
23
     * Handles a request and produces a response.
24
     *
25
     * May call other collaborating code to generate the response.
26
     */
27 2
    public function handle(ServerRequestInterface $request): ResponseInterface
28
    {
29 2
        $path = $request
30 2
            ->getUri()
31 2
            ->getPath();
32 2
        $response = $this->responseFactory->createResponse(Status::NOT_FOUND);
33 2
        $response
34 2
            ->getBody()
35 2
            ->write("We were unable to find the page \"$path\".");
36 2
        return $response;
37
    }
38
}
39