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 |
||
9 | class CTextFilterTest extends \PHPUnit_Framework_TestCase |
||
10 | { |
||
11 | /** |
||
12 | * Supported filters. |
||
13 | */ |
||
14 | private $standardFilters = [ |
||
15 | 'yamlfrontmatter', |
||
16 | 'bbcode', |
||
17 | 'clickable', |
||
18 | 'markdown', |
||
19 | 'nl2br', |
||
20 | 'shortcode', |
||
21 | ]; |
||
22 | |||
23 | |||
24 | |||
25 | /** |
||
26 | * Test. |
||
27 | * |
||
28 | * @expectedException /Mos/TextFilter/Exception |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function testJsonFrontMatterException() |
||
43 | |||
44 | |||
45 | |||
46 | /** |
||
47 | * Test. |
||
48 | * |
||
49 | * @return void |
||
50 | */ |
||
51 | public function testJsonFrontMatter() |
||
88 | |||
89 | |||
90 | |||
91 | /** |
||
92 | * Test. |
||
93 | * |
||
94 | * @expectedException /Mos/TextFilter/Exception |
||
95 | * |
||
96 | * @return void |
||
97 | */ |
||
98 | public function testYamlFrontMatterException() |
||
109 | |||
110 | |||
111 | |||
112 | /** |
||
113 | * Test. |
||
114 | * |
||
115 | * @return void |
||
116 | */ |
||
117 | public function testYamlFrontMatter() |
||
175 | |||
176 | |||
177 | |||
178 | /** |
||
179 | * Test. |
||
180 | * |
||
181 | * @return void |
||
182 | */ |
||
183 | public function testGetFilters() |
||
191 | |||
192 | |||
193 | |||
194 | |||
195 | /** |
||
196 | * Test. |
||
197 | * |
||
198 | * @return void |
||
199 | */ |
||
200 | public function testHasFilter() |
||
207 | |||
208 | |||
209 | |||
210 | |||
211 | /** |
||
212 | * Test. |
||
213 | * |
||
214 | * @expectedException /Mos/TextFilter/Exception |
||
215 | * |
||
216 | * @return void |
||
217 | */ |
||
218 | public function testHasFilterException() |
||
224 | |||
225 | |||
226 | |||
227 | |||
228 | /** |
||
229 | * Test. |
||
230 | * |
||
231 | * @return void |
||
232 | */ |
||
233 | public function testPurifier() |
||
242 | |||
243 | |||
244 | |||
245 | /** |
||
246 | * Test. |
||
247 | * |
||
248 | * @return void |
||
249 | */ |
||
250 | View Code Duplication | public function testMarkdown() |
|
259 | |||
260 | |||
261 | |||
262 | /** |
||
263 | * Test. |
||
264 | * |
||
265 | * @return void |
||
266 | */ |
||
267 | View Code Duplication | public function testMarkdownAndBBCode() |
|
276 | |||
277 | |||
278 | |||
279 | /** |
||
280 | * Test. |
||
281 | * |
||
282 | * @return void |
||
283 | */ |
||
284 | View Code Duplication | public function testMarkdownAndBBCodeAsArray() |
|
293 | |||
294 | |||
295 | |||
296 | /** |
||
297 | * Test. |
||
298 | * |
||
299 | * @return void |
||
300 | */ |
||
301 | View Code Duplication | public function testMarkdownArray() |
|
310 | |||
311 | |||
312 | |||
313 | /** |
||
314 | * Test. |
||
315 | * |
||
316 | * @return void |
||
317 | */ |
||
318 | View Code Duplication | public function testUppercase() |
|
327 | |||
328 | |||
329 | |||
330 | /** |
||
331 | * Test. |
||
332 | * |
||
333 | * @return void |
||
334 | */ |
||
335 | View Code Duplication | public function testBBCode() |
|
344 | |||
345 | |||
346 | |||
347 | /** |
||
348 | * Test. |
||
349 | * |
||
350 | * @return void |
||
351 | */ |
||
352 | View Code Duplication | public function testClickable() |
|
361 | |||
362 | |||
363 | |||
364 | /** |
||
365 | * Test. |
||
366 | * |
||
367 | * @return void |
||
368 | */ |
||
369 | View Code Duplication | public function testNl2Br() |
|
378 | |||
379 | |||
380 | |||
381 | /** |
||
382 | * Test. |
||
383 | * |
||
384 | * @return void |
||
385 | */ |
||
386 | public function testShortCodeFigure() |
||
406 | |||
407 | |||
408 | |||
409 | /** |
||
410 | * Test. |
||
411 | * |
||
412 | * @expectedException Exception |
||
413 | * |
||
414 | * @return void |
||
415 | */ |
||
416 | public function testDoItException() |
||
421 | } |
||
422 |
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.