Passed
Push — develop ( 98afd0...744340 )
by Brent
02:42
created

Config::getDependency()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Brendt\Stitcher;
4
5
/**
6
 * @todo Change parsing to work the other way around
7
 */
8
class Config
9
{
10
    /**
11
     * @param        $config
12
     * @param string $prefix
13
     *
14
     * @return array
15
     */
16
    public static function flatten(array $config, string $prefix = '') : array {
17
        $result = [];
18
19
        foreach ($config as $key => $value) {
20
            $new_key = $prefix . (empty($prefix) ? '' : '.') . $key;
21
22
            if (is_array($value)) {
23
                $result = array_merge($result, self::flatten($value, $new_key));
24
            } else {
25
                $result[$new_key] = $value;
26
            }
27
        }
28
29
        return $result;
30
    }
31
}
32