ImmutableKeyValuePair::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
namespace Chadicus\Spl\DataStructures;
3
4
/**
5
 * Defines an immutable key/value pair.
6
 */
7
final class ImmutableKeyValuePair implements KeyValuePairInterface
8
{
9
    /**
10
     * The key in the key/value pair.
11
     *
12
     * @var mixed
13
     */
14
    private $key;
15
16
    /**
17
     * The value in the key/value pair.
18
     *
19
     * @var mixed
20
     */
21
    private $value;
22
23
    /**
24
     * Construct a new KeyValuePair.
25
     *
26
     * @param mixed $key   The key of the pair.
27
     * @param mixed $value The value of the pair.
28
     */
29
    public function __construct($key, $value)
30
    {
31
        $this->key = $key;
32
        $this->value = $value;
33
    }
34
35
    /**
36
     * Gets the key in the key/value pair.
37
     *
38
     * @return mixed
39
     */
40
    public function getKey()
41
    {
42
        return $this->key;
43
    }
44
45
    /**
46
     * Gets the value in the key/value pair.
47
     *
48
     * @return mixed
49
     */
50
    public function getValue()
51
    {
52
        return $this->value;
53
    }
54
55
    /**
56
     * Ensures deep copy when cloning.
57
     *
58
     * @return void
59
     */
60
    public function __clone()
61
    {
62
        $this->key = is_object($this->key) ? clone $this->key : $this->key;
63
        $this->value = is_object($this->value) ? clone $this->value : $this->value;
64
    }
65
}
66