Conditions | 5 |
Paths | 4 |
Total Lines | 30 |
Code Lines | 13 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
10 | 16 | public function merge(ConfigCollectionInterface $mine, ConfigCollectionInterface $theirs) |
|
11 | { |
||
12 | 16 | foreach ($mine->all() as $key => $item) { |
|
13 | // If the item doesn't exist in theirs, we can just set it and continue. |
||
14 | 16 | if(!$theirs->exists($key)) { |
|
15 | 11 | $theirs->set($key, $item); |
|
16 | 11 | continue; |
|
17 | } |
||
18 | |||
19 | /** @var ConfigItemInterface **/ |
||
20 | 11 | $theirsItem = $theirs->get($key); |
|
21 | |||
22 | // Get the two values for comparison |
||
23 | 11 | $lessImportantValue = $theirsItem->getValue(); |
|
24 | 11 | $importantValue = $item->getValue(); |
|
25 | |||
26 | // Set the default value |
||
27 | 11 | $value = $importantValue; |
|
28 | |||
29 | // If its an array and the key already esists, we can use array_merge |
||
30 | 11 | if (is_array($importantValue) && is_array($lessImportantValue)) { |
|
31 | 2 | $value = array_merge($lessImportantValue, $importantValue); |
|
32 | 2 | } |
|
33 | |||
34 | // The key is not set or the value is to be overwritten |
||
35 | 11 | $theirsItem->set($value, $item->getMetaData()); |
|
36 | 16 | } |
|
37 | |||
38 | 16 | return $theirs; |
|
39 | } |
||
40 | } |
||
41 |