Passed
Pull Request — master (#18)
by
unknown
06:05
created

KeyValuePair   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 55%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 68
ccs 11
cts 20
cp 0.55
rs 10
c 1
b 0
f 0
wmc 13
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B offsetSet() 0 12 5
A offsetExists() 0 4 1
B offsetGet() 0 12 5
A offsetUnset() 0 4 1
1
<?php
2
/**
3
 * @author Boudewijn Schoon <[email protected]>
4
 * @copyright Zicht Online <http://zicht.nl>
5
 */
6
7
namespace Zicht\Itertools\lib\Containers;
8
9
/**
10
 * Class Pair
11
 *
12
 * @package Zicht\Itertools\lib\Containers
13
 */
14
class KeyValuePair implements \ArrayAccess
15
{
16
    /** @var mixed */
17
    public $key;
18
19
    /** @var mixed */
20
    public $value;
21
22
    /**
23
     * Pair constructor.
24
     *
25
     * @param mixed $key
26
     * @param mixed $value
27
     */
28 3
    public function __construct($key = null, $value = null)
29
    {
30 3
        $this->key = $key;
31 3
        $this->value = $value;
32 3
    }
33
34
    /**
35
     * @{inheritDoc}
36
     */
37 3
    public function offsetExists($offset)
38
    {
39 3
        return in_array($offset, [0, 1, 'key', 'value']);
40
    }
41
42
    /**
43
     * @{inheritDoc}
44
     */
45 3
    public function offsetGet($offset)
46
    {
47 3
        if ($offset === 0 || $offset === 'key') {
48 3
            return $this->key;
49
        }
50
51 3
        if ($offset === 1 || $offset === 'value') {
52 3
            return $this->value;
53
        }
54
55
        throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"');
56
    }
57
58
    /**
59
     * @{inheritDoc}
60
     */
61
    public function offsetSet($offset, $value)
62
    {
63
        if ($offset === 0 || $offset === 'key') {
64
            $this->key = $value;
65
        }
66
67
        if ($offset === 1 || $offset === 'value') {
68
            $this->value = $value;
69
        }
70
71
        throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"');
72
    }
73
74
    /**
75
     * @{inheritDoc}
76
     */
77
    public function offsetUnset($offset)
78
    {
79
        return $this->offsetSet($offset, null);
80
    }
81
}
82