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