TwigRenderer   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 0 Features 1
Metric Value
eloc 6
dl 0
loc 20
ccs 8
cts 8
cp 1
rs 10
c 5
b 0
f 1
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 11 1
A __construct() 0 5 1
1
<?php declare(strict_types=1);
2
3
namespace jschreuder\Middle\View;
4
5
use Psr\Http\Message\ResponseFactoryInterface;
6
use Psr\Http\Message\ResponseInterface;
7
use Psr\Http\Message\ServerRequestInterface;
8
use Twig\Environment;
9
10
final class TwigRenderer implements RendererInterface
11
{
12 2
    public function __construct(
13
        private Environment $twig,
14
        private ResponseFactoryInterface $responseFactory
15
    )
16
    {
17 2
    }
18
19 1
    public function render(ServerRequestInterface $request, ViewInterface $view): ResponseInterface
20
    {
21
        // Get new Response with HTML content type
22 1
        $response = $this->responseFactory->createResponse()->withHeader('Content-Type', 'text/html; charset=utf-8');
23
24
        // Write rendered Twig to body
25 1
        $response->getBody()->rewind();
26 1
        $response->getBody()->write($this->twig->render($view->getTemplate(), $view->getParameters()));
27 1
        $response->getBody()->rewind();
28
29 1
        return $response;
30
    }
31
}
32