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

TwigFormatter   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 5
c 5
b 1
f 1
lcom 1
cbo 3
dl 0
loc 63
ccs 16
cts 16
cp 1
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A body() 0 4 1
A template() 0 4 1
A render() 0 7 1
A output() 0 7 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