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

ContextMerger   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 10
c 0
b 0
f 0
wmc 6

1 Method

Rating   Name   Duplication   Size   Complexity  
B mergeContexts() 0 16 6
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
}