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 |
||
8 | class Result implements ResultInterface |
||
9 | { |
||
10 | /** |
||
11 | * @var array |
||
12 | */ |
||
13 | protected $data; |
||
14 | |||
15 | /** |
||
16 | * Constructor. |
||
17 | * |
||
18 | * @param array $data |
||
19 | */ |
||
20 | 7 | public function __construct(array $data) |
|
24 | |||
25 | /** |
||
26 | * Return the total amount of rows. |
||
27 | * |
||
28 | * @return int |
||
29 | */ |
||
30 | 1 | public function getTotalRows() |
|
34 | |||
35 | /** |
||
36 | * Gets the offset. |
||
37 | * |
||
38 | * @return int |
||
39 | */ |
||
40 | 1 | public function getOffset() |
|
44 | |||
45 | /** |
||
46 | * Return all rows. |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | 1 | public function getRows() |
|
54 | |||
55 | /** |
||
56 | * Return the first row. |
||
57 | * |
||
58 | * @return bool|array |
||
59 | */ |
||
60 | 1 | View Code Duplication | public function getFirstRow() |
71 | |||
72 | /** |
||
73 | * Return the last row. |
||
74 | * |
||
75 | * @return bool|array |
||
76 | */ |
||
77 | 1 | View Code Duplication | public function getLastRow() |
88 | |||
89 | /** |
||
90 | * Return the array. |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | public function toArray() |
||
98 | |||
99 | /** |
||
100 | * {@inheritdoc} |
||
101 | */ |
||
102 | 1 | public function getIterator() |
|
106 | |||
107 | /** |
||
108 | * {@inheritdoc} |
||
109 | */ |
||
110 | 1 | public function count() |
|
114 | } |
||
115 |