KeyValuePair::offsetSet()   A
last analyzed

Complexity

Conditions 5
Paths 3

Size

Total Lines 14

Duplication

Lines 14
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
nc 3
nop 2
dl 14
loc 14
ccs 8
cts 8
cp 1
crap 5
rs 9.4888
c 0
b 0
f 0
1
<?php
2
/**
3
 * @copyright Zicht Online <http://zicht.nl>
4
 */
5
6
// phpcs:disable Zicht.Commenting.PropertyComment.VarTypeAvoidMixed
7
8
namespace Zicht\Itertools\lib\Containers;
9
10
class KeyValuePair implements \ArrayAccess
11
{
12
    /** @var mixed */
13
    public $key;
14
15
    /** @var mixed */
16
    public $value;
17
18
    /**
19
     * @param mixed $key
20
     * @param mixed $value
21
     */
22 10
    public function __construct($key = null, $value = null)
23
    {
24 10
        $this->key = $key;
25 10
        $this->value = $value;
26 10
    }
27
28
    /**
29
     * {@inheritDoc}
30
     */
31 4
    public function offsetExists($offset)
32
    {
33 4
        return in_array($offset, [0, 1, 'key', 'value']);
34
    }
35
36
    /**
37
     * {@inheritDoc}
38
     */
39 5 View Code Duplication
    public function offsetGet($offset)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41 5
        if ($offset === 0 || $offset === 'key') {
42 4
            return $this->key;
43
        }
44
45 5
        if ($offset === 1 || $offset === 'value') {
46 4
            return $this->value;
47
        }
48
49 1
        throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"');
50
    }
51
52
    /**
53
     * {@inheritDoc}
54
     */
55 4 View Code Duplication
    public function offsetSet($offset, $value)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
56
    {
57 4
        if ($offset === 0 || $offset === 'key') {
58 2
            $this->key = $value;
59 2
            return;
60
        }
61
62 4
        if ($offset === 1 || $offset === 'value') {
63 2
            $this->value = $value;
64 2
            return;
65
        }
66
67 2
        throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"');
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73 2
    public function offsetUnset($offset)
74
    {
75 2
        return $this->offsetSet($offset, null);
76
    }
77
}
78