Config::__construct()   A
last analyzed

Complexity

Conditions 5
Paths 2

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 9
c 2
b 0
f 0
dl 0
loc 18
rs 9.6111
cc 5
nc 2
nop 2
1
<?php declare(strict_types=1);
2
3
namespace ShopwareEnvironmentVariables\Source\Config;
4
5
class Config extends \Shopware_Components_Config
0 ignored issues
show
Bug introduced by
The type Shopware_Components_Config was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
6
{
7
    /**
8
     * @var array
9
     */
10
    private $customConfig;
11
12
    /**
13
     * @var int
14
     */
15
    private $defaultShopId;
16
17
    /**
18
     * @param array $config
19
     * @param int $defaultShopId
20
     * @throws \Zend_Cache_Exception
21
     */
22
    public function __construct(array $config, int $defaultShopId)
23
    {
24
        parent::__construct($config);
25
        $this->customConfig = $config['custom']['config'] ?? [];
26
27
        // support for Shopware()->Config()->getByNamespace('<pluginName>', '<configName>')
28
        if (isset($config['custom']['plugins'])) {
29
            foreach ($config['custom']['plugins'] as $shopId => $pluginConfigs) {
30
                foreach ($pluginConfigs as $pluginName => $pluginConfigValues) {
31
                    foreach ($pluginConfigValues as $pluginConfigName => $pluginConfigValue) {
32
                        $pluginConfigKey = $pluginName . '::' . $pluginConfigName;
33
                        $this->customConfig[(int) $shopId][$pluginConfigKey] = $pluginConfigValue;
34
                    }
35
                }
36
            }
37
        }
38
39
        $this->defaultShopId = $defaultShopId;
40
    }
41
42
    /**
43
     * @param string $name
44
     * @return mixed
45
     */
46
    public function offsetGet($name)
47
    {
48
        return $this->customConfig[$this->getShopId()][$name] ?? parent::offsetGet($name);
49
    }
50
51
    /**
52
     * @return int
53
     */
54
    private function getShopId(): int
55
    {
56
        return $this->_shop !== null ? $this->_shop->getId() : $this->defaultShopId;
57
    }
58
}
59