Completed
Push — master ( 8bba70...b77c13 )
by Alex
02:32
created

TwigConfiguration::filesystemConfig()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0932

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 11
ccs 5
cts 7
cp 0.7143
rs 9.4285
cc 2
eloc 6
nc 2
nop 1
crap 2.0932
1
<?php
2
3
namespace AlexMasterov\EquipTwig\Configuration;
4
5
use AlexMasterov\EquipTwig\Loader\FilesystemLoader;
6
use AlexMasterov\EquipTwig\TwigFormatter;
7
use Auryn\Injector;
8
use Equip\Configuration\ConfigurationInterface;
9
use Equip\Configuration\EnvTrait;
10
use Equip\Env;
11
use Twig_Environment;
12
13
final class TwigConfiguration implements ConfigurationInterface
14
{
15
    use EnvTrait;
16
17
    /**
18
     * @param Injector $injector
19
     */
20 1
    public function apply(Injector $injector)
21
    {
22 1
        $env = $this->env;
23 1
        $options = $this->options($env);
24
25 1
        $injector->define(Twig_Environment::class, [
26 1
            'loader'   => FilesystemLoader::class,
27
            ':options' => $options
28 1
        ]);
29
30 1
        list($path,$fileExtensions) = $this->filesystemConfig($env);
31
32 1
        $injector->define(FilesystemLoader::class, [
33 1
            ':path'           => $path,
34
            ':fileExtensions' => $fileExtensions
35 1
        ]);
36 1
    }
37
38
    /**
39
     * @param Env $env
40
     *
41
     * @return array Configuration options from environment variables
42
     */
43 1
    private function options(Env $env)
44
    {
45
        $options = [
46 1
            'debug'            => $env->getValue('TWIG_DEBUG', false),
47 1
            'auto_reload'      => $env->getValue('TWIG_AUTO_RELOAD', true),
48 1
            'strict_variables' => $env->getValue('TWIG_STRICT_VARIABLES', false),
49 1
            'cache'            => $env->getValue('TWIG_CACHE', false)
50 1
        ];
51
52 1
        return $options;
53
    }
54
55
    /**
56
     * @param Env $env
57
     *
58
     * @return array
59
     */
60 1
    private function filesystemConfig(Env $env)
61
    {
62 1
        $path = $env->getValue('TWIG_TEMPLATES');
63 1
        $fileExtensions = $env->getValue('TWIG_FILE_EXTENSIONS', ['html.twig', 'twig']);
64
65 1
        if (is_string($fileExtensions)) {
66
            $fileExtensions = explode(',', $fileExtensions);
67
        }
68
69 1
        return [$path, $fileExtensions];
70
    }
71
}
72