Passed
Branch master (79e497)
by Alex
03:12
created

TwigFormatter::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 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
     * @param Twig_Environment $environment
17
     */
18
    public function __construct(Twig_Environment $environment)
19 3
    {
20
        $this->environment = $environment;
21 3
    }
22 3
23
    /**
24
     * Get a copy that uses a different template.
25
     *
26
     * @param string $template
27
     *
28
     * @return static
29 1
     */
30
    public function withTemplate($template)
31 1
    {
32
        $copy = clone $this;
33
        $copy->template = $template;
0 ignored issues
show
Bug introduced by
The property template does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
34
35
        return $copy;
36
    }
37
38
    /**
39 1
     * @inheritDoc
40
     */
41 1
    public function format($content)
42 1
    {
43
        return $this->environment->render($this->template, $content);
44 1
    }
45
}
46