Passed
Push — master ( 04a9d5...864e2a )
by Mike
06:31
created

TwigEnvironmentProvider::getTwigEnvironment()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
4
namespace Xervice\Twig\Business\Twig;
5
6
7
use Xervice\Twig\Business\Twig\Extensions\TwigExtensionCollection;
8
9
class TwigEnvironmentProvider implements TwigEnvironmentProviderInterface
10
{
11
    /**
12
     * @var \Twig_Environment
13
     */
14
    private $twig;
15
16
    /**
17
     * @var \Xervice\Twig\Business\Twig\Extensions\TwigExtensionCollection
18
     */
19
    private $extensions;
20
21
    /**
22
     * TwigEnvironmentProvider constructor.
23
     *
24
     * @param \Twig_LoaderInterface $loader
25
     * @param \Xervice\Twig\Business\Twig\Extensions\TwigExtensionCollection $extensions
26
     * @param array $config
27
     */
28 2
    public function __construct(
29
        \Twig_Environment $environment,
30
        TwigExtensionCollection $extensions
31
    ) {
32 2
        $this->twig = $environment;
33 2
        $this->extensions = $extensions;
34 2
    }
35
36
    /**
37
     * @return \Twig_Environment
38
     */
39 2
    public function getTwigEnvironment(): \Twig_Environment
40
    {
41 2
        $this->twig = $this->registerExtensions($this->twig);
42
43 2
        return $this->twig;
44
    }
45
46
    /**
47
     * @param $twig
48
     *
49
     * @return \Twig_Environment
50
     */
51 2
    protected function registerExtensions($twig): \Twig_Environment
52
    {
53 2
        foreach ($this->extensions as $extension) {
54
            $twig = $extension->register($twig);
55
        }
56 2
        return $twig;
57
    }
58
59
60
}