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 |
||
15 | trait DistillerParametersTrait |
||
16 | { |
||
17 | /** |
||
18 | * Get argument value |
||
19 | * |
||
20 | * @param string $name |
||
21 | * |
||
22 | * @return string |
||
23 | */ |
||
24 | abstract protected function getArgumentValue($name); |
||
25 | |||
26 | /** |
||
27 | * Set argument |
||
28 | * |
||
29 | * @param string $argument |
||
30 | * |
||
31 | * @return $this |
||
32 | */ |
||
33 | abstract protected function setArgument($argument); |
||
34 | |||
35 | /** |
||
36 | * Get auto rotate pages |
||
37 | * |
||
38 | * @return string |
||
39 | */ |
||
40 | public function getAutoRotatePages() |
||
49 | |||
50 | /** |
||
51 | * Set auto rotate pages |
||
52 | * |
||
53 | * @param string $autoRotatePages |
||
54 | * |
||
55 | * @param \InvalidArgumentException |
||
56 | * |
||
57 | * @return $this |
||
58 | */ |
||
59 | View Code Duplication | public function setAutoRotatePages($autoRotatePages) |
|
74 | |||
75 | /** |
||
76 | * Get binding |
||
77 | * |
||
78 | * @return string |
||
79 | */ |
||
80 | public function getBinding() |
||
89 | |||
90 | /** |
||
91 | * Set binding |
||
92 | * |
||
93 | * @param string $binding |
||
94 | * |
||
95 | * @param \InvalidArgumentException |
||
96 | * |
||
97 | * @return $this |
||
98 | */ |
||
99 | View Code Duplication | public function setBinding($binding) |
|
113 | |||
114 | /** |
||
115 | * Get compatibility level |
||
116 | * |
||
117 | * @return float |
||
118 | */ |
||
119 | public function getCompatibilityLevel() |
||
128 | |||
129 | /** |
||
130 | * Set compatibility level |
||
131 | * |
||
132 | * @param float $compatibilityLevel |
||
133 | * |
||
134 | * @return $this |
||
135 | */ |
||
136 | public function setCompatibilityLevel($compatibilityLevel) |
||
142 | |||
143 | /** |
||
144 | * Get core dist version |
||
145 | * |
||
146 | * @return int |
||
147 | */ |
||
148 | public function getCoreDistVersion() |
||
157 | |||
158 | /** |
||
159 | * Set core dist version |
||
160 | * |
||
161 | * @param int $coreDistVersion |
||
162 | * |
||
163 | * @return $this |
||
164 | */ |
||
165 | public function setCoreDistVersion($coreDistVersion) |
||
171 | |||
172 | /** |
||
173 | * Whether to do thumbnails |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function getDoThumbnails() |
||
186 | |||
187 | /** |
||
188 | * Set do thumbnails flag |
||
189 | * |
||
190 | * @param bool $doThumbnails |
||
191 | * |
||
192 | * @return $this |
||
193 | */ |
||
194 | public function setDoThumbnails($doThumbnails) |
||
200 | |||
201 | /** |
||
202 | * Get end page |
||
203 | * |
||
204 | * @return int |
||
205 | */ |
||
206 | public function getEndPage() |
||
215 | |||
216 | /** |
||
217 | * Set end page |
||
218 | * |
||
219 | * @param int $endPage |
||
220 | * |
||
221 | * @return $this |
||
222 | */ |
||
223 | public function setEndPage($endPage) |
||
229 | |||
230 | /** |
||
231 | * Get image memory |
||
232 | * |
||
233 | * @return int |
||
234 | */ |
||
235 | public function getImageMemory() |
||
244 | |||
245 | /** |
||
246 | * Set image memory |
||
247 | * |
||
248 | * @param int $imageMemory |
||
249 | * |
||
250 | * @return $this |
||
251 | */ |
||
252 | public function setImageMemory($imageMemory) |
||
258 | |||
259 | /** |
||
260 | * Get off optimizations |
||
261 | * |
||
262 | * @return int |
||
263 | */ |
||
264 | public function getOffOptimizations() |
||
273 | |||
274 | /** |
||
275 | * Set off optimizations |
||
276 | * |
||
277 | * @param int $offOptimizations |
||
278 | * |
||
279 | * @return $this |
||
280 | */ |
||
281 | public function setOffOptimizations($offOptimizations) |
||
287 | |||
288 | /** |
||
289 | * Whether to optimize |
||
290 | * |
||
291 | * @return bool |
||
292 | */ |
||
293 | public function getOptimize() |
||
302 | |||
303 | /** |
||
304 | * Set optimize flag |
||
305 | * |
||
306 | * @param bool $optimize |
||
307 | * |
||
308 | * @return $this |
||
309 | */ |
||
310 | public function setOptimize($optimize) |
||
316 | |||
317 | /** |
||
318 | * Get start page |
||
319 | * |
||
320 | * @return int |
||
321 | */ |
||
322 | public function getStartPage() |
||
331 | |||
332 | /** |
||
333 | * Set start page |
||
334 | * |
||
335 | * @param int $startPage |
||
336 | * |
||
337 | * @return $this |
||
338 | */ |
||
339 | public function setStartPage($startPage) |
||
345 | |||
346 | /** |
||
347 | * Whether to use flate compression |
||
348 | * |
||
349 | * @return bool |
||
350 | */ |
||
351 | public function getUseFlateCompression() |
||
360 | |||
361 | /** |
||
362 | * Set use flate compression flag |
||
363 | * |
||
364 | * @param bool $useFlateCompression |
||
365 | * |
||
366 | * @return $this |
||
367 | */ |
||
368 | public function setUseFlateCompression($useFlateCompression) |
||
374 | } |
||
375 |
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.