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 ParameterShadowSuperGlobalsSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | |||
19 | const TEST_FILE = 'sniff-examples/parameter_shadow_superglobals.php'; |
||
20 | |||
21 | /** |
||
22 | * testParameterShadowSuperGlobals |
||
23 | * |
||
24 | * @group parameterShadowSuperGlobals |
||
25 | * |
||
26 | * @dataProvider dataParameterShadowSuperGlobals |
||
27 | * |
||
28 | * @param string $superglobal Parameter name. |
||
29 | * @param int $line Line number where the error should occur. |
||
30 | * |
||
31 | * @return void |
||
32 | */ |
||
33 | View Code Duplication | public function testParameterShadowSuperGlobal($superglobal, $line) |
|
43 | |||
44 | /** |
||
45 | * dataParameterShadowSuperGlobals |
||
46 | * |
||
47 | * @see testParameterShadowSuperGlobals() |
||
48 | * |
||
49 | * @return array |
||
50 | */ |
||
51 | public function dataParameterShadowSuperGlobals() { |
||
64 | |||
65 | |||
66 | /** |
||
67 | * testValidParameter |
||
68 | * |
||
69 | * @group parameterShadowSuperGlobals |
||
70 | * |
||
71 | * @dataProvider dataValidParameter |
||
72 | * |
||
73 | * @param int $line The line number. |
||
74 | * |
||
75 | * @return void |
||
76 | */ |
||
77 | public function testValidParameter($line) |
||
82 | |||
83 | /** |
||
84 | * Data provider. |
||
85 | * |
||
86 | * @see testValidParameter() |
||
87 | * |
||
88 | * @return array |
||
89 | */ |
||
90 | public function dataValidParameter() |
||
98 | |||
99 | } |
||
100 |
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.