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 NewLanguageConstructsSniffTest extends BaseSniffTest |
||
|
|||
17 | { |
||
18 | const TEST_FILE = 'sniff-examples/new_language_constructs.php'; |
||
19 | |||
20 | /** |
||
21 | * testNamespaceSeparator |
||
22 | * |
||
23 | * @group NewLanguageConstructs |
||
24 | * |
||
25 | * @return void |
||
26 | */ |
||
27 | View Code Duplication | public function testNamespaceSeparator() |
|
35 | |||
36 | /** |
||
37 | * testPow |
||
38 | * |
||
39 | * @group NewLanguageConstructs |
||
40 | * |
||
41 | * @return void |
||
42 | */ |
||
43 | View Code Duplication | public function testPow() |
|
51 | |||
52 | /** |
||
53 | * testPowEquals |
||
54 | * |
||
55 | * @group NewLanguageConstructs |
||
56 | * |
||
57 | * @return void |
||
58 | */ |
||
59 | View Code Duplication | public function testPowEquals() |
|
67 | |||
68 | /** |
||
69 | * testSpaceship |
||
70 | * |
||
71 | * @group NewLanguageConstructs |
||
72 | * |
||
73 | * @return void |
||
74 | */ |
||
75 | View Code Duplication | public function testSpaceship() |
|
83 | |||
84 | /** |
||
85 | * Coalescing operator |
||
86 | * |
||
87 | * @group NewLanguageConstructs |
||
88 | * |
||
89 | * @return void |
||
90 | */ |
||
91 | public function testCoalescing() |
||
101 | |||
102 | /** |
||
103 | * Variadic functions using ... |
||
104 | * |
||
105 | * @group NewLanguageConstructs |
||
106 | * |
||
107 | * @return void |
||
108 | */ |
||
109 | View Code Duplication | public function testEllipsis() |
|
117 | } |
||
118 |
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.