TwigView   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 6 1
A configuration() 0 8 1
A __construct() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\View\Twig;
6
7
use Lit\Air\Configurator as C;
8
use Lit\Voltage\AbstractView;
9
use Psr\Http\Message\ResponseInterface;
10
use Twig\Environment;
11
use Twig\TemplateWrapper;
12
13
class TwigView extends AbstractView
14
{
15
    /**
16
     * @var TemplateWrapper
17
     */
18
    protected $template;
19
20
    public function __construct(TemplateWrapper $template)
21
    {
22
        $this->template = $template;
23
    }
24
25
    public static function configuration($loader)
26
    {
27
        return [
28
            Environment::class => C::provideParameter([
29
                C::alias(Environment::class, 'loader'),
30
                C::alias(Environment::class, 'options'),
31
            ]),
32
            C::join(Environment::class, 'loader') => $loader,
33
        ];
34
    }
35
36
    public function render(array $data = []): ResponseInterface
37
    {
38
        $body = $this->getEmptyBody();
39
        $body->write($this->template->render($data));
40
41
        return $this->response;
42
    }
43
}
44