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