Total Complexity | 6 |
Total Lines | 54 |
Duplicated Lines | 18.52 % |
Changes | 0 |
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 |
||
11 | trait ArrayAccessTrait |
||
12 | { |
||
13 | /** |
||
14 | * Determines if given offset exists in current collection. |
||
15 | * |
||
16 | * @param mixed $offset |
||
17 | * |
||
18 | * @return bool |
||
19 | */ |
||
20 | public function offsetExists($offset) |
||
21 | { |
||
22 | return isset($this->data[$offset]); |
||
23 | } |
||
24 | |||
25 | /** |
||
26 | * Puts value to given offset or appends it to current collection. |
||
27 | * |
||
28 | * @param mixed $offset |
||
29 | * @param mixed $value |
||
30 | */ |
||
31 | View Code Duplication | public function offsetSet($offset, $value) |
|
40 | } |
||
41 | |||
42 | /** |
||
43 | * Retrieves given offset from current collection. |
||
44 | * Returns NULL if no value found. |
||
45 | * |
||
46 | * @param mixed $offset |
||
47 | * |
||
48 | * @return mixed|null |
||
49 | */ |
||
50 | public function offsetGet($offset) |
||
51 | { |
||
52 | return isset($this->data[$offset]) ? $this->data[$offset] : null; |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Drops given offset from current collection. |
||
57 | * |
||
58 | * @param mixed $offset |
||
59 | */ |
||
60 | public function offsetUnset($offset) |
||
65 | } |
||
66 | } |
||
67 |
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.