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 EmptyNonVariableSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | const TEST_FILE = 'sniff-examples/empty_non_variable.php'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * testEmptyNonVariable |
||
| 22 | * |
||
| 23 | * @group emptyNonVariable |
||
| 24 | * |
||
| 25 | * @dataProvider dataEmptyNonVariable |
||
| 26 | * |
||
| 27 | * @param int $line The line number. |
||
| 28 | * |
||
| 29 | * @return void |
||
| 30 | */ |
||
| 31 | View Code Duplication | public function testEmptyNonVariable($line) |
|
| 39 | |||
| 40 | /** |
||
| 41 | * Data provider. |
||
| 42 | * |
||
| 43 | * @see testEmptyNonVariable() |
||
| 44 | * |
||
| 45 | * @return array |
||
| 46 | */ |
||
| 47 | public function dataEmptyNonVariable() |
||
| 78 | |||
| 79 | |||
| 80 | /** |
||
| 81 | * testNoViolation |
||
| 82 | * |
||
| 83 | * @group emptyNonVariable |
||
| 84 | * |
||
| 85 | * @dataProvider dataNoViolation |
||
| 86 | * |
||
| 87 | * @param int $line The line number. |
||
| 88 | * |
||
| 89 | * @return void |
||
| 90 | */ |
||
| 91 | public function testNoViolation($line) |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Data provider. |
||
| 99 | * |
||
| 100 | * @see testNoViolation() |
||
| 101 | * |
||
| 102 | * @return array |
||
| 103 | */ |
||
| 104 | View Code Duplication | public function dataNoViolation() |
|
| 120 | } |
||
| 121 |
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.