Passed
Push — master ( 003724...f241d1 )
by Brent
02:47
created

Config::flatten()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

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