Passed
Push — master ( f74aa0...4214e2 )
by Alexander
05:54
created

NotFoundHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 27
rs 10
ccs 7
cts 7
cp 1
wmc 2

2 Methods

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