TwigViewListener::supports()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 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