Total Complexity | 7 |
Total Lines | 69 |
Duplicated Lines | 27.54 % |
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 |
||
12 | trait LazyIterator |
||
13 | { |
||
14 | /** |
||
15 | * Performs lazy load checks and loads items if required. |
||
16 | */ |
||
17 | abstract protected function checkLazyLoad(); |
||
18 | |||
19 | /** |
||
20 | * Current iterator item. |
||
21 | * |
||
22 | * @return mixed|null |
||
23 | */ |
||
24 | View Code Duplication | public function current() |
|
|
|||
25 | { |
||
26 | $this->checkLazyLoad(); |
||
27 | |||
28 | $currentKey = $this->keys[$this->position]; |
||
29 | |||
30 | return isset($this->items[$currentKey]) ? $this->items[$currentKey] : null; |
||
31 | } |
||
32 | |||
33 | /** |
||
34 | * Current iterator position. |
||
35 | * |
||
36 | * @return mixed |
||
37 | */ |
||
38 | public function key() |
||
43 | } |
||
44 | |||
45 | /** |
||
46 | * Increments iterator position. |
||
47 | */ |
||
48 | public function next() |
||
53 | } |
||
54 | |||
55 | /** |
||
56 | * Rewinds iterator back to first position. |
||
57 | */ |
||
58 | public function rewind() |
||
59 | { |
||
60 | $this->checkLazyLoad(); |
||
61 | |||
62 | $this->position = 0; |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * Determines if there is some value at current iterator position. |
||
67 | * |
||
68 | * @return bool |
||
69 | */ |
||
70 | View Code Duplication | public function valid() |
|
81 | } |
||
82 | } |
||
83 |
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.