Completed
Branch master (ebdf13)
by Alex
03:29 queued 01:42
created

TwigFormatter::context()   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 Lukasoppermann\Httpstatus\Httpstatus;
8
9
class TwigFormatter extends HtmlFormatter
10
{
11
    /**
12
     * @var \Twig_Environment
13
     */
14
    protected $environment;
15
16
    /**
17
     * @param \Twig_Environment $environment
18
     * @param Httpstatus        $httpStatus
19
     */
20 3
    public function __construct(\Twig_Environment $environment, Httpstatus $httpStatus)
21
    {
22 3
        $this->environment = $environment;
23 3
        parent::__construct($httpStatus);
24 3
    }
25
26
    /**
27
     * @param TemplatePayload $payload
28
     *
29
     * @return string
30
     */
31 1
    public function body(PayloadInterface $payload)
32
    {
33 1
        return $this->render($payload);
34
    }
35
36
    /**
37
     * @param PayloadInterface $payload
38
     *
39
     * @return string
40
     */
41 1
    protected function render(PayloadInterface $payload)
42
    {
43 1
        $template = $this->template($payload);
44 1
        $context = $this->context($payload);
45
46 1
        return $this->environment->render($template, $context);
47
    }
48
49
    /**
50
     * @param PayloadInterface $payload
51
     *
52
     * @return string
53
     */
54 1
    protected function template(PayloadInterface $payload)
55
    {
56 1
        return $payload->getOutput()['template'];
57
    }
58
59
    /**
60
     * @param PayloadInterface $payload
61
     *
62
     * @return array $context
63
     */
64 1
    protected function context(PayloadInterface $payload)
65
    {
66 1
        $context = $payload->getOutput();
67 1
        unset($context['template']);
68
69 1
        return $context;
70
    }
71
}
72