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 NewFunctionArrayDereferencingSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | const TEST_FILE = 'sniff-examples/new_function_array_dereferencing.php'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * testArrayDereferencing |
||
| 22 | * |
||
| 23 | * @group functionArrayDereferencing |
||
| 24 | * |
||
| 25 | * @return void |
||
| 26 | */ |
||
| 27 | View Code Duplication | public function testArrayDereferencing() |
|
| 35 | |||
| 36 | |||
| 37 | /** |
||
| 38 | * testNoViolation |
||
| 39 | * |
||
| 40 | * @group functionArrayDereferencing |
||
| 41 | * |
||
| 42 | * @dataProvider dataNoViolation |
||
| 43 | * |
||
| 44 | * @param int $line Line number with valid code. |
||
| 45 | * |
||
| 46 | * @return void |
||
| 47 | */ |
||
| 48 | public function testNoViolation($line) |
||
| 53 | |||
| 54 | /** |
||
| 55 | * dataNoViolation |
||
| 56 | * |
||
| 57 | * @see testNoViolation() |
||
| 58 | * |
||
| 59 | * @return array |
||
| 60 | */ |
||
| 61 | public function dataNoViolation() { |
||
| 67 | } |
||
| 68 |
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.