KeyValuePair   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 68
Duplicated Lines 38.24 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 26
loc 68
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0
wmc 13
lcom 1
cbo 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A offsetExists() 0 4 1
A offsetGet() 12 12 5
A offsetSet() 14 14 5
A offsetUnset() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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