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() |
||
68 | |||
69 | |||
70 | /** |
||
71 | * testNoViolation |
||
72 | * |
||
73 | * @group emptyNonVariable |
||
74 | * |
||
75 | * @dataProvider dataNoViolation |
||
76 | * |
||
77 | * @param int $line The line number. |
||
78 | * |
||
79 | * @return void |
||
80 | */ |
||
81 | public function testNoViolation($line) |
||
86 | |||
87 | /** |
||
88 | * Data provider. |
||
89 | * |
||
90 | * @see testNoViolation() |
||
91 | * |
||
92 | * @return array |
||
93 | */ |
||
94 | View Code Duplication | public function dataNoViolation() |
|
108 | } |
||
109 |
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.