Completed
Push — master ( 641a43...8c4162 )
by Alex
27:33 queued 24:31
created

TwigFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 4
Bugs 0 Features 1
Metric Value
c 4
b 0
f 1
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Asmaster\EquipTwig;
4
5
use Equip\Adr\PayloadInterface;
6
use Equip\Formatter\HtmlFormatter;
7
use Twig_Environment as TwigEnvironment;
8
9
final class TwigFormatter extends HtmlFormatter
10
{
11
    /**
12
     * @var TwigEnvironment
13
     */
14
    private $environment;
15
16
    /**
17
     * @param TwigEnvironment $environment
18
     */
19 3
    public function __construct(TwigEnvironment $environment)
20
    {
21 3
        $this->environment = $environment;
22 3
    }
23
24
    /**
25
     * @param PayloadInterface $payload
26
     *
27
     * @return string
28
     */
29
    public function body(PayloadInterface $payload)
30
    {
31
        return $this->render($payload);
32
    }
33
34
    /**
35
     * @param PayloadInterface $payload
36
     *
37
     * @return string
38
     */
39
    private function render(PayloadInterface $payload)
40
    {
41
        $template = $payload->getSetting('template');
42
        $output = $payload->getOutput();
43
44
        return $this->environment->render($template, $output);
45
    }
46
}
47