NotFoundHandler   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A handle() 0 8 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Aidphp\Framework;
6
7
use Psr\Http\Server\RequestHandlerInterface;
8
use Psr\Http\Message\ResponseFactoryInterface;
9
use Interop\Renderer\RendererInterface;
10
use Psr\Http\Message\ServerRequestInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
class NotFoundHandler implements RequestHandlerInterface
14
{
15
    public const TEMPLATE = 'not-found';
16
17
    protected $factory;
18
    protected $renderer;
19
    protected $template;
20
21 1
    public function __construct(ResponseFactoryInterface $factory, RendererInterface $renderer, string $template = self::TEMPLATE)
22
    {
23 1
        $this->factory  = $factory;
24 1
        $this->renderer = $renderer;
25 1
        $this->template = $template;
26 1
    }
27
28 1
    public function handle(ServerRequestInterface $req): ResponseInterface
29
    {
30 1
        $res = $this->factory->createResponse(404);
31
32 1
        $res->getBody()->write($this->renderer->render($this->template));
33
34 1
        return $res;
35
    }
36
}