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

Installer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
eloc 9
dl 0
loc 31
rs 10
c 0
b 0
f 0
ccs 10
cts 10
cp 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A install() 0 11 1
A __construct() 0 3 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