Completed
Pull Request — 2.x (#29)
by Akihito
01:35
created

OptionProvider::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 2
1
<?php
2
/**
3
 * This file is part of the Madapaja.TwigModule package.
4
 *
5
 * @license http://opensource.org/licenses/MIT MIT
6
 */
7
namespace Madapaja\TwigModule;
8
9
use BEAR\AppMeta\AbstractAppMeta;
10
use Ray\Di\Di\Named;
11
use Ray\Di\ProviderInterface;
12
13
class OptionProvider implements ProviderInterface
14
{
15
    /**
16
     * @var AbstractAppMeta
17
     */
18
    private $appMeta;
19
20
    /**
21
     * @var bool
22
     */
23
    private $isDebug;
24
25
    /**
26
     * @Named("isDebug=Madapaja\TwigModule\Annotation\TwigDebug")
27
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
28
     */
29
    public function __construct(AbstractAppMeta $appMeta, bool $isDebug = false)
30
    {
31
        $this->appMeta = $appMeta;
32
        $this->isDebug = $isDebug;
33
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38
    public function get()
39
    {
40
        $tmpDir = $this->appMeta->tmpDir . '/twig';
41
        ! \file_exists($tmpDir) && \mkdir($tmpDir);
42
        $options = [
43
            'debug' => $this->isDebug,
44
            'cache' => $tmpDir
45
        ];
46
47
        return $options;
48
    }
49
}
50