Completed
Push — master ( 742ff7...9d59a2 )
by Nikola
09:00
created

merge-config.php ➔ mergeConfig()   A

Complexity

Conditions 6
Paths 5

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
nc 5
nop 2
dl 0
loc 18
rs 9.0444
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Phoundation;
6
7
function mergeConfig(array $config1, array $config2): array
8
{
9
    foreach ($config2 as $key => $value) {
10
        if (array_key_exists($key, $config1)) {
11
            if (is_int($key)) {
12
                $config1[] = $value;
13
            } elseif (is_array($value) && is_array($config1[$key])) {
14
                $config1[$key] = mergeConfig($config1[$key], $value);
15
            } else {
16
                $config1[$key] = $value;
17
            }
18
        } else {
19
            $config1[$key] = $value;
20
        }
21
    }
22
23
    return $config1;
24
}
25