Passed
Push — master ( aec349...e9c1f2 )
by Alexander
04:11
created

ReverseBlockMerge::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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