Passed
Pull Request — master (#34)
by Alexander
26:50 queued 11:51
created

ReverseBlockMerge::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace Yiisoft\Arrays\Modifier;
4
5
/**
6
 * Result will be ordered by source the opposite to actual merge.
7
 * It is especially useful for merging module config with core config
8
 * where more specific config has more priority.
9
 *
10
 * For example:
11
 *
12
 * ```php
13
 * $one = [
14
 *    'f' => 'f1',
15
 *    'b' => [
16
 *        'b1' => 'b11',
17
 *        'b2' => 'b33',
18
 *     ],
19
 *     'g' => 'g1',
20
 *     'h',
21
 * ];
22
 *
23
 * $two = [
24
 *     'a' => 'a1',
25
 *     'b' => [
26
 *         'b1' => 'bv1',
27
 *         'b2' => 'bv2',
28
 *     ],
29
 *     'd',
30
 * ];
31
 *
32
 * $three = [
33
 *     'a' => 'a2',
34
 *     'c' => 'c1',
35
 *     'b' => [
36
 *         'b2' => 'bv22',
37
 *         'b3' => 'bv3',
38
 *     ],
39
 *     'e',
40
 *     ReverseBlockMerge::class => new ReverseBlockMerge(),
41
 * ];
42
 *
43
 * $result = ArrayHelper::mergeReverse($one, $two, $three);
44
 * ```
45
 *
46
 * Will result in:
47
 *
48
 * ```php
49
 * [
50
 *     'a' => 'a2',
51
 *     'c' => 'c1',
52
 *     'b' => [
53
 *         'b2' => 'bv22',
54
 *         'b3' => 'bv3',
55
 *         'b1' => 'bv1',
56
 *     ]
57
 *     0 => 'e',
58
 *     1 => 'd',
59
 *     'f' => 'f1',
60
 *     'g' => 'g1',
61
 *     2 => 'h',
62
 * ]
63
 * ```
64
 */
65
class ReverseBlockMerge implements ModifierInterface
66
{
67
    public function apply(array $data, string $key): array
68
    {
69
        return $data;
70
    }
71
}
72