Passed
Push — master ( c3bafa...50dd0b )
by Alexander
02:05
created

NotFoundHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
    private ResponseFactoryInterface $responseFactory;
19
20 10
    public function __construct(ResponseFactoryInterface $responseFactory)
21
    {
22 10
        $this->responseFactory = $responseFactory;
23 10
    }
24
25
    /**
26
     * Handles a request and produces a response.
27
     *
28
     * May call other collaborating code to generate the response.
29
     */
30 2
    public function handle(ServerRequestInterface $request): ResponseInterface
31
    {
32 2
        $path = $request->getUri()->getPath();
33 2
        $response = $this->responseFactory->createResponse(Status::NOT_FOUND);
34 2
        $response->getBody()->write("We were unable to find the page \"$path\".");
35 2
        return $response;
36
    }
37
}
38