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 ConstantArraysUsingDefineSniffTest extends BaseSniffTest |
||
17 | { |
||
18 | const TEST_FILE = 'sniff-examples/constant_arrays_using_define.php'; |
||
19 | |||
20 | /** |
||
21 | * Verify that checking for a specific version works |
||
22 | * |
||
23 | * @group constantArraysUsingDefine |
||
24 | * |
||
25 | * @dataProvider dataConstantArraysUsingDefine |
||
26 | * |
||
27 | * @param int $line The line number. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | View Code Duplication | public function testConstantArraysUsingDefine($line) |
|
39 | |||
40 | /** |
||
41 | * Data provider dataConstantArraysUsingDefine. |
||
42 | * |
||
43 | * @see testConstantArraysUsingDefine() |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function dataConstantArraysUsingDefine() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * testNoViolation |
||
58 | * |
||
59 | * @group constantArraysUsingDefine |
||
60 | * |
||
61 | * @dataProvider dataNoViolation |
||
62 | * |
||
63 | * @param int $line The line number. |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | public function testNoViolation($line) |
||
72 | |||
73 | /** |
||
74 | * Data provider. |
||
75 | * |
||
76 | * @see testNoViolation() |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public function dataNoViolation() |
||
86 | |||
87 | } |
||
88 |
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.