Completed
Push — 2.1 ( ba7352...41aa5d )
by Dmitry
21:34 queued 05:31
created

ReplaceArrayValue::__set_state()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 1
crap 6
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
/**
11
 * Object that represents the replacement of array value while performing [[ArrayHelper::merge()]].
12
 *
13
 * Usage example:
14
 *
15
 * ```php
16
 * $array1 = [
17
 *     'ids' => [
18
 *         1,
19
 *     ],
20
 *     'validDomains' => [
21
 *         'example.com',
22
 *         'www.example.com',
23
 *     ],
24
 * ];
25
 *
26
 * $array2 = [
27
 *     'ids' => [
28
 *         2,
29
 *     ],
30
 *     'validDomains' => new \yii\helpers\ReplaceArrayValue([
31
 *         'yiiframework.com',
32
 *         'www.yiiframework.com',
33
 *     ]),
34
 * ];
35
 *
36
 * $result = \yii\helpers\ArrayHelper::merge($array1, $array2);
37
 * ```
38
 *
39
 * The result will be
40
 *
41
 * ```php
42
 * [
43
 *     'ids' => [
44
 *         1,
45
 *         2,
46
 *     ],
47
 *     'validDomains' => [
48
 *         'yiiframework.com',
49
 *         'www.yiiframework.com',
50
 *     ],
51
 * ]
52
 * ```
53
 *
54
 * @author Robert Korulczyk <[email protected]>
55
 * @since 2.0.10
56
 */
57
class ReplaceArrayValue
58
{
59
    /**
60
     * @var mixed value used as replacement.
61
     */
62
    public $value;
63
64
    /**
65
     * Constructor.
66
     * @param mixed $value value used as replacement.
67
     */
68 1
    public function __construct($value)
69
    {
70 1
        $this->value = $value;
71 1
    }
72
73
    /**
74
     * Restores class state after using `var_export()`.
75
     *
76
     * @param array $state
77
     * @return self
78
     * @see var_export()
79
     * @since 2.1.0
80
     */
81
    public static function __set_state($state)
82
    {
83
        if (!isset($state['value'])) {
84
            throw new InvalidConfigException('Failed to instantiate class "ReplaceArrayValue". Required parameter "value" is missing');
85
        }
86
87
        return new self($state['value']);
88
    }
89
}
90