TwigFormatter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace AlexMasterov\EquipTwig;
5
6
use Equip\Formatter\HtmlFormatter;
7
use Twig_Environment;
8
9
final class TwigFormatter extends HtmlFormatter
10
{
11
    /**
12
     * @var Twig_Environment
13
     */
14
    private $environment;
15
16
    /**
17
     * @var string
18
     */
19
    private $template;
20
21 3
    public function __construct(Twig_Environment $environment)
22
    {
23 3
        $this->environment = $environment;
24 3
    }
25
26
    /**
27
     * Get a copy that uses a different template.
28
     *
29
     * @param string $template
30
     *
31
     * @return static
32
     */
33 1
    public function withTemplate($template)
34
    {
35 1
        $copy = clone $this;
36 1
        $copy->template = $template;
37
38 1
        return $copy;
39
    }
40
41
    /**
42
     * @inheritDoc
43
     */
44 1
    public function format($content)
45
    {
46 1
        return $this->environment->render($this->template, $content);
47
    }
48
}
49