Pair   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Test Coverage

Coverage 71.43%

Importance

Changes 0
Metric Value
wmc 6
eloc 10
dl 0
loc 73
ccs 10
cts 14
cp 0.7143
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setValue() 0 3 1
A __construct() 0 4 1
A __get() 0 4 2
A getValue() 0 3 1
A getKey() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PHPCollections\Collections;
6
7
/**
8
 * A simple key / value pair
9
 * object representation.
10
 */
11
class Pair
12
{
13
    /**
14
     * The key for the Pair object.
15
     *
16
     * @var mixed
17
     */
18
    private $key;
19
20
    /**
21
     * The value for the Pair object.
22
     *
23
     * @var mixed
24
     */
25
    private $value;
26
27
    /**
28
     * Initializes class properties.
29
     *
30
     * @param mixed $key
31
     * @param mixed $value
32
     */
33 27
    public function __construct($key, $value)
34
    {
35 27
        $this->key = $key;
36 27
        $this->value = $value;
37 27
    }
38
39
    /**
40
     * Allows access to the key
41
     * property by its value.
42
     *
43
     * @param string $name
44
     *
45
     * @return mixed
46
     */
47
    public function __get(string $name)
48
    {
49
        if ($name === $this->key) {
50
            return $this->value;
51
        }
52
    }
53
54
    /**
55
     * Returns the key property.
56
     *
57
     * @return mixed
58
     */
59 16
    public function getKey()
60
    {
61 16
        return $this->key;
62
    }
63
64
    /**
65
     * Returns the value property.
66
     *
67
     * @return mixed
68
     */
69 18
    public function getValue()
70
    {
71 18
        return $this->value;
72
    }
73
74
    /**
75
     * Sets the value of the value property.
76
     *
77
     * @param mixed $value
78
     *
79
     * @return void
80
     */
81 1
    public function setValue($value): void
82
    {
83 1
        $this->value = $value;
84 1
    }
85
}
86