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 PregReplaceEModifierSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | |||
19 | const TEST_FILE = 'sniff-examples/preg_replace_e_modifier.php'; |
||
20 | |||
21 | /** |
||
22 | * testDeprecatedEModifier |
||
23 | * |
||
24 | * @group pregReplaceEModifier |
||
25 | * |
||
26 | * @dataProvider dataDeprecatedEModifier |
||
27 | * |
||
28 | * @param int $line Line number where the error should occur. |
||
29 | * @param string $functionName Function name. |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | View Code Duplication | public function testDeprecatedEModifier($line, $functionName = 'preg_replace') |
|
44 | |||
45 | /** |
||
46 | * dataDeprecatedEModifier |
||
47 | * |
||
48 | * @see testDeprecatedEModifier() |
||
49 | * |
||
50 | * @return array |
||
51 | */ |
||
52 | public function dataDeprecatedEModifier() { |
||
86 | |||
87 | |||
88 | /** |
||
89 | * testNoViolation |
||
90 | * |
||
91 | * @group pregReplaceEModifier |
||
92 | * |
||
93 | * @dataProvider dataNoViolation |
||
94 | * |
||
95 | * @param int $line Line number where no error should occur. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function testNoViolation($line) |
||
110 | |||
111 | /** |
||
112 | * dataNoViolation |
||
113 | * |
||
114 | * @see testNoViolation() |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | public function dataNoViolation() { |
||
147 | |||
148 | } |
||
149 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.