1 | <?php |
||
7 | class Priority |
||
8 | { |
||
9 | /** |
||
10 | * Merges an array of values into a collection |
||
11 | * |
||
12 | * @param array $mine Map of key to array with value and metadata sub-keys |
||
13 | * @param MutableConfigCollectionInterface $theirs |
||
14 | * @return MutableConfigCollectionInterface |
||
15 | */ |
||
16 | 17 | public static function merge(array $mine, MutableConfigCollectionInterface $theirs) |
|
17 | { |
||
18 | 17 | foreach ($mine as $class => $item) { |
|
19 | // Ensure we have value/metadata keys |
||
20 | 17 | $item = static::normaliseItem($item); |
|
21 | 17 | $value = $item['value']; |
|
22 | 17 | $metadata = $item['metadata']; |
|
23 | |||
24 | // If the item doesn't exist in theirs, we can just set it and continue. |
||
25 | 17 | $theirValue = $theirs->get($class, null, true); |
|
|
|||
26 | 17 | if (!isset($theirValue)) { |
|
27 | $theirs->set($class, null, $value, $metadata); |
||
28 | continue; |
||
29 | } |
||
30 | |||
31 | // If its an array and the key already esists, we can use array_merge |
||
32 | 17 | if (is_array($value) && is_array($theirValue)) { |
|
33 | 7 | $value = static::mergeArray($value, $theirValue); |
|
34 | 7 | } |
|
35 | |||
36 | // Preserve metadata |
||
37 | 17 | if (!$metadata) { |
|
38 | 6 | $theirMetadata = $theirs->getMetadata(); |
|
39 | 6 | if (isset($theirMetadata[$class])) { |
|
40 | $metadata = $theirMetadata[$class]; |
||
41 | } |
||
42 | 6 | } |
|
43 | 17 | $theirs->set($class, null, $value, $metadata); |
|
44 | 17 | } |
|
45 | |||
46 | 17 | return $theirs; |
|
47 | } |
||
48 | |||
49 | /** |
||
50 | * Deep merges a high priorty array into a lower priority array, overwriting duplicate |
||
51 | * keys. If the keys are integers, then the merges acts like array_merge() and adds a new |
||
52 | * item. |
||
53 | * |
||
54 | * @param array $highPriority |
||
55 | * @param array $lowPriority |
||
56 | * |
||
57 | * @return array |
||
58 | */ |
||
59 | 9 | public static function mergeArray(array $highPriority, array $lowPriority) |
|
90 | |||
91 | /** |
||
92 | * Returns a normalised array with value/metadata keys |
||
93 | * |
||
94 | * @param array |
||
95 | * |
||
96 | * @return array |
||
97 | */ |
||
98 | 17 | protected static function normaliseItem(array $item) |
|
110 | } |
||
111 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: