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

ShopConfig   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 44
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getConfig() 0 11 3
A get() 0 3 1
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
}