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

ReplaceValue::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
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
 * Object that represents the replacement of array value while performing {@see Merger::merge()}.
9
 *
10
 * Usage example:
11
 *
12
 * ```php
13
 * $array1 = [
14
 *     'ids' => [
15
 *         1,
16
 *     ],
17
 *     'validDomains' => [
18
 *         'example.com',
19
 *         'www.example.com',
20
 *     ],
21
 * ];
22
 *
23
 * $array2 = [
24
 *     'ids' => [
25
 *         2,
26
 *     ],
27
 *     'validDomains' => new \Yiisoft\Composer\Config\Merger\Modifier\ReplaceValue([
28
 *         'yiiframework.com',
29
 *         'www.yiiframework.com',
30
 *     ]),
31
 * ];
32
 *
33
 * $result = Merger::merge($array1, $array2);
34
 * ```
35
 *
36
 * The result will be
37
 *
38
 * ```php
39
 * [
40
 *     'ids' => [
41
 *         1,
42
 *         2,
43
 *     ],
44
 *     'validDomains' => [
45
 *         'yiiframework.com',
46
 *         'www.yiiframework.com',
47
 *     ],
48
 * ]
49
 * ```
50
 */
51
final class ReplaceValue implements ModifierInterface
52
{
53
    /**
54
     * @var mixed value used as replacement
55
     */
56
    public $value;
57
58
    /**
59
     * @param mixed $value value used as replacement
60
     */
61 2
    public function __construct($value)
62
    {
63 2
        $this->value = $value;
64 2
    }
65
66 2
    public function apply(array $data, $key): array
67
    {
68
        /** @var mixed */
69 2
        $data[$key] = $this->value;
70
71 2
        return $data;
72
    }
73
}
74