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

TwigEnvironmentProvider   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 48
ccs 10
cts 11
cp 0.9091
rs 10
c 0
b 0
f 0
wmc 4

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A registerExtensions() 0 6 2
A getTwigEnvironment() 0 5 1
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
}