Completed
Push — master ( dbd031...7b005e )
by Alex
02:16
created

TwigFormatter::template()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Asmaster\EquipTwig;
4
5
use Equip\Payload;
6
use Equip\Adr\PayloadInterface;
7
use Equip\Formatter\HtmlFormatter;
8
use Lukasoppermann\Httpstatus\Httpstatus;
9
10
class TwigFormatter extends HtmlFormatter
11
{
12
    /**
13
     * @var \Twig_Environment
14
     */
15
    protected $environment;
16
17
    /**
18
     * @param \Twig_Environment $environment
19
     * @param Httpstatus        $httpStatus
20
     */
21 3
    public function __construct(\Twig_Environment $environment, Httpstatus $httpStatus)
22
    {
23 3
        $this->environment = $environment;
24 3
        parent::__construct($httpStatus);
25 3
    }
26
27
    /**
28
     * @param TemplatePayload $payload
29
     *
30
     * @return string
31
     */
32
    public function body(PayloadInterface $payload)
33
    {
34
        return $this->render($payload);
35
    }
36
37
    /**
38
     * @param PayloadInterface $payload
39
     *
40
     * @return string
41
     */
42
    protected function render(PayloadInterface $payload)
43
    {
44
        $template = $this->template($payload);
45
        $context = $this->context($payload);
46
47
        return $this->environment->render($template, $context);
48
    }
49
50
    /**
51
     * @param PayloadInterface $payload
52
     *
53
     * @return string
54
     */
55
    protected function template(PayloadInterface $payload)
56
    {
57
        return $payload->getOutput()['template'];
58
    }
59
60
    /**
61
     * @param PayloadInterface $payload
62
     *
63
     * @return array $context
64
     */
65
    protected function context(PayloadInterface $payload)
66
    {
67
        $context = $payload->getOutput();
68
        unset($context['template']);
69
70
        return $context;
71
    }
72
}
73