Completed
Push — master ( 1bb6c0...07dbd8 )
by Alex
22:05
created

TwigFormatter::output()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 4
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;
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 1
    public function body(PayloadInterface $payload)
33
    {
34 1
        return $this->render($payload);
35
    }
36
37
    /**
38
     * @param PayloadInterface $payload
39
     *
40
     * @return string
41
     */
42 1
    protected function render(PayloadInterface $payload)
43
    {
44 1
        $template = $this->template($payload);
45 1
        $output = $this->output($payload);
46
47 1
        return $this->environment->render($template, $output);
48
    }
49
50
    /**
51
     * @param PayloadInterface $payload
52
     *
53
     * @return string Template name
54
     */
55 1
    protected function template(PayloadInterface $payload)
56
    {
57 1
        return $payload->getOutput()['template'];
58
    }
59
60
    /**
61
     * @param PayloadInterface $payload
62
     *
63
     * @return array $output
64
     */
65 1
    protected function output(PayloadInterface $payload)
66
    {
67 1
        $output = $payload->getOutput();
68 1
        unset($output['template']);
69
70 1
        return $output;
71
    }
72
}
73