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 LateStaticBindingSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | const TEST_FILE = 'sniff-examples/late_static_binding.php'; |
||
19 | |||
20 | /** |
||
21 | * testLateStaticBinding |
||
22 | * |
||
23 | * @group lateStaticBinding |
||
24 | * |
||
25 | * @dataProvider dataLateStaticBinding |
||
26 | * |
||
27 | * @param int $line The line number. |
||
28 | * |
||
29 | * @return void |
||
30 | */ |
||
31 | View Code Duplication | public function testLateStaticBinding($line) |
|
39 | |||
40 | /** |
||
41 | * Data provider. |
||
42 | * |
||
43 | * @see testLateStaticBinding() |
||
44 | * |
||
45 | * @return array |
||
46 | */ |
||
47 | public function dataLateStaticBinding() |
||
54 | |||
55 | |||
56 | /** |
||
57 | * testLateStaticBindingOutsideClassScope |
||
58 | * |
||
59 | * @group lateStaticBinding |
||
60 | * |
||
61 | * @dataProvider dataLateStaticBindingOutsideClassScope |
||
62 | * |
||
63 | * @param int $line The line number. |
||
64 | * |
||
65 | * @return void |
||
66 | */ |
||
67 | public function testLateStaticBindingOutsideClassScope($line) |
||
72 | |||
73 | /** |
||
74 | * Data provider. |
||
75 | * |
||
76 | * @see testLateStaticBindingOutsideClassScope() |
||
77 | * |
||
78 | * @return array |
||
79 | */ |
||
80 | public function dataLateStaticBindingOutsideClassScope() |
||
86 | |||
87 | |||
88 | /** |
||
89 | * testNoViolation |
||
90 | * |
||
91 | * @group lateStaticBinding |
||
92 | * |
||
93 | * @dataProvider dataNoViolation |
||
94 | * |
||
95 | * @param int $line The line number. |
||
96 | * |
||
97 | * @return void |
||
98 | */ |
||
99 | public function testNoViolation($line) |
||
104 | |||
105 | /** |
||
106 | * Data provider. |
||
107 | * |
||
108 | * @see testNoViolation() |
||
109 | * |
||
110 | * @return array |
||
111 | */ |
||
112 | View Code Duplication | public function dataNoViolation() |
|
121 | } |
||
122 |
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.