TwigViewListener   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 1
cbo 2
dl 0
loc 27
ccs 8
cts 8
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getContent() 0 6 1
A supports() 0 4 1
1
<?php
2
3
namespace Zenstruck\ControllerUtil\EventListener;
4
5
use Zenstruck\ControllerUtil\View;
6
7
/**
8
 * @author Kevin Bond <[email protected]>
9
 */
10
class TwigViewListener extends ViewListener
11
{
12
    protected $twig;
13
14 3
    public function __construct(\Twig_Environment $twig)
15
    {
16 3
        $this->twig = $twig;
17 3
    }
18
19
    /**
20
     * {@inheritdoc}
21
     */
22 1
    protected function getContent(View $view, $format)
23
    {
24 1
        $template = $this->twig->resolveTemplate($view->getTemplate());
25
26 1
        return $template->render($view->getDataAsArray());
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32 2
    protected function supports(View $view, $format)
33
    {
34 2
        return null !== $view->getTemplate();
35
    }
36
}
37