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 |
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.