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 |
||
16 | class MbstringReplaceEModifierSniffTest extends BaseSniffTest |
||
17 | { |
||
18 | const TEST_FILE = 'sniff-examples/mbstring_replace_e_modifier.php'; |
||
19 | |||
20 | /** |
||
21 | * testMbstringEModifier |
||
22 | * |
||
23 | * @group mbstringEModifier |
||
24 | * |
||
25 | * @dataProvider dataMbstringEModifier |
||
26 | * |
||
27 | * @param int $line The line number. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | public function testMbstringEModifier($line) |
||
42 | |||
43 | /** |
||
44 | * Data provider. |
||
45 | * |
||
46 | * @see testMbstringEModifier() |
||
47 | * |
||
48 | * @return array |
||
49 | */ |
||
50 | public function dataMbstringEModifier() |
||
58 | |||
59 | |||
60 | /** |
||
61 | * testNoViolation |
||
62 | * |
||
63 | * @group mbstringEModifier |
||
64 | * |
||
65 | * @dataProvider dataNoViolation |
||
66 | * |
||
67 | * @param int $line The line number. |
||
68 | * |
||
69 | * @return void |
||
70 | */ |
||
71 | public function testNoViolation($line) |
||
76 | |||
77 | /** |
||
78 | * Data provider. |
||
79 | * |
||
80 | * @see testNoViolation() |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | View Code Duplication | public function dataNoViolation() |
|
95 | } |
||
96 |
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.