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

ShopConfig::get()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
}