Params   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 90%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
eloc 16
c 1
b 0
f 0
dl 0
loc 42
ccs 18
cts 20
cp 0.9
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnvKey() 0 3 1
A pushValues() 0 14 5
A pushEnvVars() 0 9 2
A paramsRequired() 0 3 1
A calcValues() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Composer\Config\Config;
6
7
/**
8
 * Params class represents output configuration file with params definitions.
9
 */
10
class Params extends ConfigOutput
11
{
12 2
    protected function calcValues(array $sources): array
13
    {
14 2
        return $this->pushEnvVars(parent::calcValues($sources));
15
    }
16
17 2
    protected function pushEnvVars(array $data): array
18
    {
19 2
        if (empty($data)) {
20 2
            return [];
21
        }
22
23
        $env = $this->builder->getConfig('envs')->getValues();
24
25
        return self::pushValues($data, $env);
26
    }
27
28 2
    public static function pushValues(array $data, array $values, string $prefix = null)
29
    {
30 2
        foreach ($data as $key => &$value) {
31 2
            $subkey = $prefix===null ? $key : "${prefix}_$key";
32
33 2
            $envkey = self::getEnvKey($subkey);
34 2
            if (isset($values[$envkey])) {
35 2
                $value = $values[$envkey];
36 2
            } elseif (is_array($value)) {
37 2
                $value = self::pushValues($value, $values, $subkey);
38
            }
39
        }
40
41 2
        return $data;
42
    }
43
44 2
    private static function getEnvKey(string $key): string
45
    {
46 2
        return strtoupper(strtr($key, '.-', '__'));
47
    }
48
49 2
    protected function paramsRequired(): bool
50
    {
51 2
        return false;
52
    }
53
}
54