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 |
||
18 | class StateComparator |
||
19 | { |
||
20 | /** |
||
21 | * @var TableState |
||
22 | */ |
||
23 | private $initial = null; |
||
24 | |||
25 | /** |
||
26 | * @var TableState |
||
27 | */ |
||
28 | private $current = null; |
||
29 | |||
30 | /** |
||
31 | * @param TableState $initial |
||
32 | * @param TableState $current |
||
33 | */ |
||
34 | public function __construct(TableState $initial, TableState $current) |
||
39 | |||
40 | /** |
||
41 | * @return bool |
||
42 | */ |
||
43 | public function hasChanges(): bool |
||
67 | |||
68 | /** |
||
69 | * @return bool |
||
70 | */ |
||
71 | public function isRenamed(): bool |
||
75 | |||
76 | /** |
||
77 | * @return bool |
||
78 | */ |
||
79 | public function isPrimaryChanged(): bool |
||
83 | |||
84 | /** |
||
85 | * @return AbstractColumn[] |
||
86 | */ |
||
87 | View Code Duplication | public function addedColumns(): array |
|
98 | |||
99 | /** |
||
100 | * @return AbstractColumn[] |
||
101 | */ |
||
102 | View Code Duplication | public function droppedColumns(): array |
|
113 | |||
114 | /** |
||
115 | * Returns array where each value contain current and initial element state. |
||
116 | * |
||
117 | * @return array |
||
118 | */ |
||
119 | View Code Duplication | public function alteredColumns(): array |
|
137 | |||
138 | /** |
||
139 | * @return AbstractIndex[] |
||
140 | */ |
||
141 | View Code Duplication | public function addedIndexes(): array |
|
152 | |||
153 | /** |
||
154 | * @return AbstractIndex[] |
||
155 | */ |
||
156 | View Code Duplication | public function droppedIndexes(): array |
|
167 | |||
168 | /** |
||
169 | * Returns array where each value contain current and initial element state. |
||
170 | * |
||
171 | * @return array |
||
172 | */ |
||
173 | View Code Duplication | public function alteredIndexes(): array |
|
191 | |||
192 | /** |
||
193 | * @return AbstractReference[] |
||
194 | */ |
||
195 | View Code Duplication | public function addedForeigns(): array |
|
206 | |||
207 | /** |
||
208 | * @return AbstractReference[] |
||
209 | */ |
||
210 | View Code Duplication | public function droppedForeigns(): array |
|
221 | |||
222 | /** |
||
223 | * Returns array where each value contain current and initial element state. |
||
224 | * |
||
225 | * @return array |
||
226 | */ |
||
227 | View Code Duplication | public function alteredForeigns(): array |
|
245 | |||
246 | /** |
||
247 | * @return array |
||
248 | */ |
||
249 | public function __debugInfo() |
||
273 | } |
||
274 |
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.