Completed
Push — master ( 56570e...2c8793 )
by Gabriel
07:17
created

DefinitionsCollection   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 87
Duplicated Lines 5.75 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 95.65%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 5
loc 87
ccs 22
cts 23
cp 0.9565
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A all() 0 4 1
A replace() 0 4 1
A has() 0 4 1
A get() 0 4 1
A set() 0 4 1
A offsetExists() 0 4 1
A offsetGet() 0 4 1
A offsetSet() 5 8 2

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
namespace Nip\Dispatcher\Resolver\Cache;
4
5
/**
6
 * Class DefinitionsCollection
7
 * @package Nip\Dispatcher\Resolver\Cache
8
 */
9
class DefinitionsCollection
10
{
11
    protected $items = [];
12
13
    /**
14
     * DefinitionsCollection constructor.
15
     * @param array $items
16
     */
17 4
    public function __construct(array $items)
18
    {
19 4
        $this->items = $items;
20 4
    }
21
22
    /**
23
     * @return array
24
     */
25 5
    public function all()
26
    {
27 5
        return $this->items;
28
    }
29
30
    /**
31
     * @param $items
32
     * @return array
33
     */
34 3
    public function replace($items)
35
    {
36 3
        return $this->items = $items + $this->items;
37
    }
38
39
    /**
40
     * @param $offset
41
     * @return bool
42
     */
43 3
    public function has($offset)
44
    {
45 3
        return $this->offsetExists($offset);
46
    }
47
48
    /**
49
     * @param $offset
50
     * @return mixed
51
     */
52 3
    public function get($offset)
53
    {
54 3
        return $this->offsetGet($offset);
55
    }
56
57
    /**
58
     * @param $offset
59
     * @param $value
60
     * @return mixed
61
     */
62 3
    public function set($offset, $value)
63
    {
64 3
        $this->offsetSet($offset, $value);
65 3
    }
66
67
    /**
68
     * @inheritdoc
69
     */
70 3
    public function offsetExists($offset)
71
    {
72 3
        return isset($this->items[$offset]);
73
    }
74
75
    /**
76
     * @inheritdoc
77
     */
78 3
    public function offsetGet($offset)
79
    {
80 3
        return $this->items[$offset];
81
    }
82
83
    /**
84
     * @inheritdoc
85
     * @param string $value
86
     */
87 3
    public function offsetSet($offset, $value)
88
    {
89 3 View Code Duplication
        if ($offset == null) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
90
            $this->items[] = $value;
91
        } else {
92 3
            $this->items[$offset] = $value;
93
        }
94 3
    }
95
}
96