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

Config::load()   B

Complexity

Conditions 4
Paths 8

Size

Total Lines 38
Code Lines 25

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 25
nc 8
nop 2
dl 0
loc 38
rs 8.5806
c 1
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