Installer::__construct()   A
last analyzed

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 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
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;
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 13
    public function __construct(Pipeline $pipeline)
21
    {
22 13
        $this->pipeline = $pipeline;
23 13
    }
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 13
    public function install(Environment $twig): Environment
33
    {
34 13
        $twig = clone $twig;
35
36 13
        $extension = new Extension($this->pipeline);
37 13
        $twig->addExtension($extension);
38
39 13
        $compiler = new PatchingCompiler($twig);
40 13
        $twig->setCompiler($compiler);
41
42 13
        return $twig;
43
    }
44
}
45