Passed
Push — master ( cf7a49...93599e )
by Phillip
01:37
created

ShopConfig::getConfig()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 0
dl 0
loc 11
ccs 6
cts 6
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Deployee\Plugins\ShopwareTasks\Shop;
4
5
6
class ShopConfig
7
{
8
    /**
9
     * @var string
10
     */
11
    private $configFilePath;
12
13
    /**
14
     * @var array
15
     */
16
    private $config;
17
18
    /**
19
     * ShopConfig constructor.
20
     * @param string $configFilePath
21
     */
22 2
    public function __construct(string $configFilePath)
23
    {
24 2
        $this->configFilePath = $configFilePath;
25 2
    }
26
27
    /**
28
     * @param string $id
29
     * @return mixed|null
30
     */
31 2
    public function get(string $id)
32
    {
33 2
        return $this->getConfig()[$id] ?? null;
34
    }
35
36
    /**
37
     * @return array
38
     */
39 2
    private function getConfig(): array
40
    {
41 2
        if($this->config === null){
42 2
            if(!is_file($this->configFilePath)){
43 1
                throw new \InvalidArgumentException("Path to shopware config was not found or is invalid");
44
            }
45
46 1
            $this->config = require($this->configFilePath);
47
        }
48
49 1
        return $this->config;
50
    }
51
}