Passed
Push — master ( e49660...49ecd8 )
by Alexander
13:27 queued 11:59
created

ReverseBlockMerge   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 5
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 3 1
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
 * The modifier should be specified as
11
 *
12
 * ```php
13
 * ReverseBlockMerge::class => new ReverseBlockMerge(),
14
 * ```
15
 *
16
 * For example:
17
 *
18
 * ```php
19
 * $one = [
20
 *    'f' => 'f1',
21
 *    'b' => [
22
 *        'b1' => 'b11',
23
 *        'b2' => 'b33',
24
 *     ],
25
 *     'g' => 'g1',
26
 *     'h',
27
 * ];
28
 *
29
 * $two = [
30
 *     'a' => 'a1',
31
 *     'b' => [
32
 *         'b1' => 'bv1',
33
 *         'b2' => 'bv2',
34
 *     ],
35
 *     'd',
36
 * ];
37
 *
38
 * $three = [
39
 *     'a' => 'a2',
40
 *     'c' => 'c1',
41
 *     'b' => [
42
 *         'b2' => 'bv22',
43
 *         'b3' => 'bv3',
44
 *     ],
45
 *     'e',
46
 *     ReverseBlockMerge::class => new ReverseBlockMerge(),
47
 * ];
48
 *
49
 * $result = ArrayHelper::mergeReverse($one, $two, $three);
50
 * ```
51
 *
52
 * Will result in:
53
 *
54
 * ```php
55
 * [
56
 *     'a' => 'a2',
57
 *     'c' => 'c1',
58
 *     'b' => [
59
 *         'b2' => 'bv22',
60
 *         'b3' => 'bv3',
61
 *         'b1' => 'bv1',
62
 *     ]
63
 *     0 => 'e',
64
 *     1 => 'd',
65
 *     'f' => 'f1',
66
 *     'g' => 'g1',
67
 *     2 => 'h',
68
 * ]
69
 * ```
70
 *
71
 * @see ArrayHelper::performReverseBlockMerge()
72
 */
73
final class ReverseBlockMerge implements ModifierInterface
74
{
75 1
    public function apply(array $data, string $key): array
76
    {
77 1
        return $data;
78
    }
79
}
80