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

Config::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
rs 9.4285
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