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 NewKeywordsSniffTest extends BaseSniffTest |
||
|
|
|||
| 17 | { |
||
| 18 | const TEST_FILE = 'sniff-examples/new_keywords.php'; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Test allow_url_include |
||
| 22 | * |
||
| 23 | * @group newKeywords |
||
| 24 | * |
||
| 25 | * @return void |
||
| 26 | */ |
||
| 27 | View Code Duplication | public function testDirMagicConstant() |
|
| 35 | |||
| 36 | /** |
||
| 37 | * Test insteadof |
||
| 38 | * |
||
| 39 | * @group newKeywords |
||
| 40 | * |
||
| 41 | * @return void |
||
| 42 | */ |
||
| 43 | View Code Duplication | public function testInsteadOf() |
|
| 54 | |||
| 55 | /** |
||
| 56 | * Test namespace keyword |
||
| 57 | * |
||
| 58 | * @group newKeywords |
||
| 59 | * |
||
| 60 | * @return void |
||
| 61 | */ |
||
| 62 | View Code Duplication | public function testNamespaceKeyword() |
|
| 70 | |||
| 71 | /** |
||
| 72 | * testNamespaceConstant |
||
| 73 | * |
||
| 74 | * @group newKeywords |
||
| 75 | * |
||
| 76 | * @return void |
||
| 77 | */ |
||
| 78 | View Code Duplication | public function testNamespaceConstant() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * Test trait keyword |
||
| 89 | * |
||
| 90 | * @group newKeywords |
||
| 91 | * |
||
| 92 | * @return void |
||
| 93 | */ |
||
| 94 | View Code Duplication | public function testTraitKeyword() |
|
| 102 | |||
| 103 | /** |
||
| 104 | * Test trait magic constant |
||
| 105 | * |
||
| 106 | * @group newKeywords |
||
| 107 | * |
||
| 108 | * @return void |
||
| 109 | */ |
||
| 110 | View Code Duplication | public function testTraitConstant() |
|
| 118 | |||
| 119 | /** |
||
| 120 | * Test the use keyword |
||
| 121 | * |
||
| 122 | * @group newKeywords |
||
| 123 | * |
||
| 124 | * @return void |
||
| 125 | */ |
||
| 126 | View Code Duplication | public function testUse() |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Test yield |
||
| 137 | * |
||
| 138 | * @group newKeywords |
||
| 139 | * |
||
| 140 | * @return void |
||
| 141 | */ |
||
| 142 | View Code Duplication | public function testYield() |
|
| 150 | |||
| 151 | /** |
||
| 152 | * testFinally |
||
| 153 | * |
||
| 154 | * @group newKeywords |
||
| 155 | * |
||
| 156 | * @return void |
||
| 157 | */ |
||
| 158 | View Code Duplication | public function testFinally() |
|
| 166 | |||
| 167 | /** |
||
| 168 | * testNowdoc |
||
| 169 | * |
||
| 170 | * @group newKeywords |
||
| 171 | * |
||
| 172 | * @requires PHP 5.3 |
||
| 173 | * |
||
| 174 | * @return void |
||
| 175 | */ |
||
| 176 | View Code Duplication | public function testNowdoc() |
|
| 186 | |||
| 187 | /** |
||
| 188 | * testConst |
||
| 189 | * |
||
| 190 | * @group newKeywords |
||
| 191 | * |
||
| 192 | * @return void |
||
| 193 | */ |
||
| 194 | View Code Duplication | public function testConst() |
|
| 204 | |||
| 205 | /** |
||
| 206 | * testCallable |
||
| 207 | * |
||
| 208 | * @group newKeywords |
||
| 209 | * |
||
| 210 | * @return void |
||
| 211 | */ |
||
| 212 | public function testCallable() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * testGoto |
||
| 222 | * |
||
| 223 | * @group newKeywords |
||
| 224 | * |
||
| 225 | * @return void |
||
| 226 | */ |
||
| 227 | View Code Duplication | public function testGoto() |
|
| 235 | |||
| 236 | /** |
||
| 237 | * testHaltCompiler |
||
| 238 | * |
||
| 239 | * @group newKeywords |
||
| 240 | * |
||
| 241 | * @requires PHP 5.3 |
||
| 242 | * |
||
| 243 | |||
| 244 | * @return void |
||
| 245 | */ |
||
| 246 | public function testHaltCompiler() |
||
| 264 | } |
||
| 265 |
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.