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 | View Code Duplication | public function dataEmptyNonVariable() |
|
48 | { |
||
49 | return array( |
||
50 | array(17), |
||
51 | array(18), |
||
52 | |||
53 | array(20), |
||
54 | array(21), |
||
55 | array(22), |
||
56 | array(23), |
||
57 | |||
58 | array(25), |
||
59 | array(26), |
||
60 | array(27), |
||
61 | array(28), |
||
62 | array(29), |
||
63 | array(30), |
||
64 | array(31), |
||
65 | array(32), |
||
66 | |||
67 | array(34), |
||
68 | array(35), |
||
69 | array(37), |
||
70 | array(38), |
||
71 | array(39), |
||
72 | array(40), |
||
73 | |||
74 | array(42), |
||
75 | array(43), |
||
76 | ); |
||
77 | } |
||
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() |
|
136 | } |
||
137 |
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.