Completed
Push — master ( 0e3a66...27a5b1 )
by Dmitry
13:54
created

ReplaceArrayValue   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 42.86%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 35
ccs 3
cts 7
cp 0.4286
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __set_state() 0 8 2
1
<?php
2
/**
3
 * @link http://www.yiiframework.com/
4
 * @copyright Copyright (c) 2008 Yii Software LLC
5
 * @license http://www.yiiframework.com/license/
6
 */
7
8
namespace yii\helpers;
9
10
use yii\base\InvalidConfigException;
11
12
/**
13
 * Object that represents the replacement of array value while performing [[ArrayHelper::merge()]].
14
 *
15
 * Usage example:
16
 *
17
 * ```php
18
 * $array1 = [
19
 *     'ids' => [
20
 *         1,
21
 *     ],
22
 *     'validDomains' => [
23
 *         'example.com',
24
 *         'www.example.com',
25
 *     ],
26
 * ];
27
 *
28
 * $array2 = [
29
 *     'ids' => [
30
 *         2,
31
 *     ],
32
 *     'validDomains' => new \yii\helpers\ReplaceArrayValue([
33
 *         'yiiframework.com',
34
 *         'www.yiiframework.com',
35
 *     ]),
36
 * ];
37
 *
38
 * $result = \yii\helpers\ArrayHelper::merge($array1, $array2);
39
 * ```
40
 *
41
 * The result will be
42
 *
43
 * ```php
44
 * [
45
 *     'ids' => [
46
 *         1,
47
 *         2,
48
 *     ],
49
 *     'validDomains' => [
50
 *         'yiiframework.com',
51
 *         'www.yiiframework.com',
52
 *     ],
53
 * ]
54
 * ```
55
 *
56
 * @author Robert Korulczyk <[email protected]>
57
 * @since 2.0.10
58
 */
59
class ReplaceArrayValue
60
{
61
    /**
62
     * @var mixed value used as replacement.
63
     */
64
    public $value;
65
66
67
    /**
68
     * Constructor.
69
     * @param mixed $value value used as replacement.
70
     */
71 1
    public function __construct($value)
72
    {
73 1
        $this->value = $value;
74 1
    }
75
76
    /**
77
     * Restores class state after using `var_export()`.
78
     *
79
     * @param array $state
80
     * @return ReplaceArrayValue
81
     * @throws InvalidConfigException when $state property does not contain `value` parameter
82
     * @see var_export()
83
     * @since 2.0.16
84
     */
85
    public static function __set_state($state)
86
    {
87
        if (!isset($state['value'])) {
88
            throw new InvalidConfigException('Failed to instantiate class "Instance". Required parameter "id" is missing');
89
        }
90
91
        return new self($state['value']);
92
    }
93
}
94