NotFoundHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 9
dl 0
loc 21
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A handle() 0 10 1
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