Passed
Push — master ( 59db0f...9fb939 )
by Brent
04:37
created

Config   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 24
rs 10
c 1
b 0
f 0
wmc 5
lcom 0
cbo 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B flatten() 0 15 5
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) && count($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