Passed
Pull Request — master (#19)
by
unknown
03:59
created

KeyValuePair::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 2
dl 0
loc 5
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
c 1
b 0
f 0
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 9
    public function __construct($key = null, $value = null)
29
    {
30 9
        $this->key = $key;
31 9
        $this->value = $value;
32 9
    }
33
34
    /**
35
     * @{inheritDoc}
36
     */
37 4
    public function offsetExists($offset)
38
    {
39 4
        return in_array($offset, [0, 1, 'key', 'value']);
40
    }
41
42
    /**
43
     * @{inheritDoc}
44
     */
45 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...
46
    {
47 5
        if ($offset === 0 || $offset === 'key') {
48 4
            return $this->key;
49
        }
50
51 5
        if ($offset === 1 || $offset === 'value') {
52 4
            return $this->value;
53
        }
54
55 1
        throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"');
56
    }
57
58
    /**
59
     * @{inheritDoc}
60
     */
61 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...
62
    {
63 4
        if ($offset === 0 || $offset === 'key') {
64 2
            $this->key = $value;
65 2
            return;
66
        }
67
68 4
        if ($offset === 1 || $offset === 'value') {
69 2
            $this->value = $value;
70 2
            return;
71
        }
72
73 2
        throw new \InvalidArgumentException('$OFFSET must be either 0, 1, "key", or "value"');
74
    }
75
76
    /**
77
     * @{inheritDoc}
78
     */
79 2
    public function offsetUnset($offset)
80
    {
81 2
        return $this->offsetSet($offset, null);
82
    }
83
}
84