Reader   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 5
eloc 14
c 2
b 1
f 0
dl 0
loc 50
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 2
A getByPluginName() 0 10 3
1
<?php declare(strict_types=1);
2
3
namespace ShopwareEnvironmentVariables\Source\Config;
4
5
use Shopware\Components\Plugin\ConfigReader;
0 ignored issues
show
Bug introduced by
The type Shopware\Components\Plugin\ConfigReader 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
use Shopware\Models\Shop\Shop;
0 ignored issues
show
Bug introduced by
The type Shopware\Models\Shop\Shop 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...
7
use ShopwareEnvironmentVariables\Source\Helper\ShopProvider;
8
9
class Reader implements ConfigReader
10
{
11
    /**
12
     * @var ConfigReader
13
     */
14
    private $configReader;
15
16
    /**
17
     * @var array
18
     */
19
    private $customEnvironmentVariables;
20
21
    /**
22
     * @var ShopProvider
23
     */
24
    private $shopProvider;
25
26
    /**
27
     * @param ConfigReader $configReader
28
     * @param ShopProvider $shopProvider
29
     * @param array $customEnvironmentVariables
30
     */
31
    public function __construct(
32
        ConfigReader $configReader,
33
        ShopProvider $shopProvider,
34
        array $customEnvironmentVariables
35
    ) {
36
        $this->configReader = $configReader;
37
        $this->customEnvironmentVariables = [];
38
        if (isset($customEnvironmentVariables['plugins'])) {
39
            $this->customEnvironmentVariables = $customEnvironmentVariables['plugins'];
40
        }
41
        $this->shopProvider = $shopProvider;
42
    }
43
44
    /**
45
     * @param string $pluginName
46
     * @param Shop|null $shop
47
     * @return array
48
     */
49
    public function getByPluginName($pluginName, Shop $shop = null): array
50
    {
51
        $result = $this->configReader->getByPluginName($pluginName, $shop);
52
        $shopId = $shop !== null ? $shop->getId() : $this->shopProvider->getShopId();
53
54
        if (!isset($this->customEnvironmentVariables[$shopId][$pluginName])) {
55
            return $result;
56
        }
57
58
        return array_merge($result, $this->customEnvironmentVariables[$shopId][$pluginName]);
59
    }
60
}
61