Completed
Push — master ( ee9d02...8bba70 )
by Alex
04:07
created

TwigFormatter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 43
rs 10
c 0
b 0
f 0
ccs 9
cts 9
cp 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A withTemplate() 0 7 1
A format() 0 4 1
1
<?php
2
3
namespace AlexMasterov\EquipTwig;
4
5
use Equip\Formatter\HtmlFormatter;
6
use Twig_Environment;
7
8
final class TwigFormatter extends HtmlFormatter
9
{
10
    /**
11
     * @var Twig_Environment
12
     */
13
    private $environment;
14
15
    /**
16
     * @var string
17
     */
18
    private $template;
19
20
    /**
21
     * @param Twig_Environment $environment
22
     */
23 3
    public function __construct(Twig_Environment $environment)
24
    {
25 3
        $this->environment = $environment;
26 3
    }
27
28
    /**
29
     * Get a copy that uses a different template.
30
     *
31
     * @param string $template
32
     *
33
     * @return static
34
     */
35 1
    public function withTemplate($template)
36
    {
37 1
        $copy = clone $this;
38 1
        $copy->template = $template;
39
40 1
        return $copy;
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 1
    public function format($content)
47
    {
48 1
        return $this->environment->render($this->template, $content);
49
    }
50
}
51