Completed
Pull Request — master (#10)
by David
02:33
created

ContextMerger::mergeContexts()   B

Complexity

Conditions 6
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 10
nc 4
nop 2
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
1
<?php
2
3
4
namespace TheCodingMachine\CMS\Utils;
5
6
7
class ContextMerger implements ContextMergerInterface
8
{
9
    public function mergeContexts(array $context1, array $context2): array
10
    {
11
        $finalContext = $context1;
12
        foreach ($context2 as $key => $value) {
13
            if (is_numeric($key)) {
14
                $finalContext[] = $value;
15
                continue;
16
            }
17
18
            if (isset($finalContext[$key]) && is_array($finalContext[$key]) && is_array($value)) {
19
                $finalContext[$key] = $this->mergeContexts($finalContext[$key], $value);
20
                continue;
21
            }
22
            $finalContext[$key] = $value;
23
        }
24
        return $finalContext;
25
    }
26
}