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 |
||
| 13 | class SimpleTest extends TestCase |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @covers \EasyDictionary\Dictionary\Simple |
||
| 17 | */ |
||
| 18 | public function testClassExistence() |
||
| 22 | |||
| 23 | /** |
||
| 24 | * @covers ::__construct |
||
| 25 | * @covers ::setName |
||
| 26 | * @covers ::setDataProvider |
||
| 27 | * @covers ::getDataProvider |
||
| 28 | * @covers ::getCache |
||
| 29 | * @covers ::getData |
||
| 30 | * @covers ::loadData |
||
| 31 | */ |
||
| 32 | public function testGetDataWithDataProvider() |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @covers ::__construct |
||
| 46 | * @covers ::setName |
||
| 47 | * @covers ::getDataProvider |
||
| 48 | * @covers ::getCache |
||
| 49 | * @covers ::getData |
||
| 50 | * @covers ::loadData |
||
| 51 | */ |
||
| 52 | public function testGetDataWithoutDataProvider() |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @covers ::__construct |
||
| 60 | * @covers ::setName |
||
| 61 | * @covers ::getName |
||
| 62 | * @covers ::setCache |
||
| 63 | * @covers ::setDataProvider |
||
| 64 | * @covers ::getDataProvider |
||
| 65 | * @covers ::getCache |
||
| 66 | * @covers ::getData |
||
| 67 | * @covers ::loadData |
||
| 68 | */ |
||
| 69 | View Code Duplication | public function testSaveDataToCache() |
|
| 86 | |||
| 87 | /** |
||
| 88 | * @covers ::__construct |
||
| 89 | * @covers ::setName |
||
| 90 | * @covers ::getName |
||
| 91 | * @covers ::setCache |
||
| 92 | * @covers ::setDataProvider |
||
| 93 | * @covers ::getDataProvider |
||
| 94 | * @covers ::getCache |
||
| 95 | * @covers ::getData |
||
| 96 | * @covers ::loadData |
||
| 97 | */ |
||
| 98 | View Code Duplication | public function testSaveDataToCacheThrowError() |
|
| 117 | |||
| 118 | /** |
||
| 119 | * @covers ::__construct |
||
| 120 | * @covers ::setName |
||
| 121 | * @covers ::count |
||
| 122 | * @covers ::setDataProvider |
||
| 123 | * @covers ::getDataProvider |
||
| 124 | * @covers ::getCache |
||
| 125 | * @covers ::getData |
||
| 126 | * @covers ::loadData |
||
| 127 | */ |
||
| 128 | public function testDataCount() |
||
| 141 | |||
| 142 | /** |
||
| 143 | * @covers ::__construct |
||
| 144 | * @covers ::setName |
||
| 145 | * @covers ::getCache |
||
| 146 | * @covers ::getData |
||
| 147 | * @covers ::getDataProvider |
||
| 148 | * @covers ::getDefaultView |
||
| 149 | * @covers ::getIterator |
||
| 150 | * @covers ::setDataProvider |
||
| 151 | * @covers ::loadData |
||
| 152 | */ |
||
| 153 | View Code Duplication | public function testDataIteratorWithoutView() |
|
| 170 | |||
| 171 | /** |
||
| 172 | * @covers ::__construct |
||
| 173 | * @covers ::setName |
||
| 174 | * @covers ::getCache |
||
| 175 | * @covers ::getData |
||
| 176 | * @covers ::getDataProvider |
||
| 177 | * @covers ::setDataProvider |
||
| 178 | * @covers ::getDefaultView |
||
| 179 | * @covers ::setDefaultView |
||
| 180 | * @covers ::getIterator |
||
| 181 | * @covers ::loadData |
||
| 182 | * @covers ::withView |
||
| 183 | */ |
||
| 184 | public function testDataIteratorWithGoodView() |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @covers ::__construct |
||
| 209 | * @covers ::setName |
||
| 210 | * @covers ::getCache |
||
| 211 | * @covers ::getData |
||
| 212 | * @covers ::getDataProvider |
||
| 213 | * @covers ::setDataProvider |
||
| 214 | * @covers ::getDefaultView |
||
| 215 | * @covers ::getIterator |
||
| 216 | * @covers ::loadData |
||
| 217 | * @covers ::withView |
||
| 218 | */ |
||
| 219 | View Code Duplication | public function testDataIteratorWithBadView() |
|
| 236 | |||
| 237 | /** |
||
| 238 | * @covers ::__construct |
||
| 239 | * @covers ::setName |
||
| 240 | * @covers ::getCache |
||
| 241 | * @covers ::getData |
||
| 242 | * @covers ::getDataProvider |
||
| 243 | * @covers ::setDataProvider |
||
| 244 | * @covers ::getDefaultView |
||
| 245 | * @covers ::getIterator |
||
| 246 | * @covers ::loadData |
||
| 247 | * @covers ::setSearchFields |
||
| 248 | * @covers ::search |
||
| 249 | * @covers ::getSearchFields |
||
| 250 | */ |
||
| 251 | public function testDataIteratorSearchInFlatData() |
||
| 268 | |||
| 269 | /** |
||
| 270 | * @covers ::__construct |
||
| 271 | * @covers ::setName |
||
| 272 | * @covers ::getCache |
||
| 273 | * @covers ::getData |
||
| 274 | * @covers ::getDataProvider |
||
| 275 | * @covers ::setDataProvider |
||
| 276 | * @covers ::getDefaultView |
||
| 277 | * @covers ::getIterator |
||
| 278 | * @covers ::loadData |
||
| 279 | * @covers ::setSearchFields |
||
| 280 | * @covers ::search |
||
| 281 | * @covers ::setSearchFields |
||
| 282 | * @covers ::getSearchFields |
||
| 283 | */ |
||
| 284 | public function testDataIteratorSearchInArrayData() |
||
| 300 | } |
||
| 301 | |||
| 306 |