Passed
Push — master ( 016046...20ba69 )
by Victor
50s
created

Installer::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 1
nc 1
nop 1
crap 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Shoot\Shoot;
5
6
use Shoot\Shoot\Twig\PatchingCompiler;
7
use Twig_Environment as Environment;
8
9
/**
10
 * Installs Shoot in an instance of Twig.
11
 */
12
final class Installer
13
{
14
    /** @var Pipeline */
15
    private $pipeline;
16
17
    /**
18
     * @param Pipeline $pipeline
19
     */
20 8
    public function __construct(Pipeline $pipeline)
21
    {
22 8
        $this->pipeline = $pipeline;
23 8
    }
24
25
    /**
26
     * Returns a Twig instance with Shoot installed. Does not modify the original instance.
27
     *
28
     * @param Environment $twig
29
     *
30
     * @return Environment
31
     */
32 8
    public function install(Environment $twig): Environment
33
    {
34 8
        $twig = clone $twig;
35
36 8
        $extension = new Extension($this->pipeline);
37 8
        $twig->addExtension($extension);
38
39 8
        $compiler = new PatchingCompiler($twig);
40 8
        $twig->setCompiler($compiler);
41
42 8
        return $twig;
43
    }
44
}
45