Completed
Push — master ( a835c9...ff904d )
by Alex
04:03
created

TwigFormatter::__construct()   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 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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 3
20
    /**
21 3
     * @param Twig_Environment $environment
22 3
     */
23
    public function __construct(Twig_Environment $environment)
24
    {
25
        $this->environment = $environment;
26
    }
27
28
    /**
29 1
     * Get a copy that uses a different template.
30
     *
31 1
     * @param string $template
32
     *
33
     * @return static
34
     */
35
    public function withTemplate($template)
36
    {
37
        $copy = clone $this;
38
        $copy->template = $template;
39 1
40
        return $copy;
41 1
    }
42 1
43
    /**
44 1
     * @inheritDoc
45
     */
46
    public function format($content)
47
    {
48
        return $this->environment->render($this->template, $content);
49
    }
50
}
51