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 |
||
20 | class BannerTest extends UnitTestCase |
||
21 | { |
||
22 | /** |
||
23 | * @var \DERHANSEN\SfBanners\Domain\Model\Banner |
||
24 | */ |
||
25 | protected $fixture; |
||
26 | |||
27 | /** |
||
28 | * Set up |
||
29 | * |
||
30 | * @return void |
||
31 | */ |
||
32 | public function setUp() |
||
36 | |||
37 | /** |
||
38 | * Tear down |
||
39 | * |
||
40 | * @return void |
||
41 | */ |
||
42 | public function tearDown() |
||
46 | |||
47 | /** |
||
48 | * Test if title can be set |
||
49 | * |
||
50 | * @test |
||
51 | * @return void |
||
52 | */ |
||
53 | public function titleCanBeSetTest() |
||
59 | |||
60 | /** |
||
61 | * Test if description can be set |
||
62 | * |
||
63 | * @test |
||
64 | * @return void |
||
65 | */ |
||
66 | public function descriptionCanBeSetTest() |
||
72 | |||
73 | /** |
||
74 | * Test if type can be set |
||
75 | * |
||
76 | * @test |
||
77 | * @return void |
||
78 | */ |
||
79 | public function typeCanBeSetTest() |
||
85 | |||
86 | /** |
||
87 | * Test if margin can be set |
||
88 | * |
||
89 | * @test |
||
90 | * @return void |
||
91 | */ |
||
92 | public function marginTopCanBeSetTest() |
||
98 | |||
99 | /** |
||
100 | * Test if margin can be set |
||
101 | * |
||
102 | * @test |
||
103 | * @return void |
||
104 | */ |
||
105 | public function marginRightCanBeSetTest() |
||
111 | |||
112 | /** |
||
113 | * Test if margin can be set |
||
114 | * |
||
115 | * @test |
||
116 | * @return void |
||
117 | */ |
||
118 | public function marginBottomCanBeSetTest() |
||
124 | |||
125 | /** |
||
126 | * Test if margin can be set |
||
127 | * |
||
128 | * @test |
||
129 | * @return void |
||
130 | */ |
||
131 | public function marginLeftCanBeSetTest() |
||
137 | |||
138 | /** |
||
139 | * @test |
||
140 | */ |
||
141 | public function getLinkRespectsFalMediaSetting() |
||
160 | |||
161 | /** |
||
162 | * Test if html can be set |
||
163 | * |
||
164 | * @test |
||
165 | * @return void |
||
166 | */ |
||
167 | public function htmlCanBeSetTest() |
||
173 | |||
174 | /** |
||
175 | * Test if impressionsmax can be set |
||
176 | * |
||
177 | * @test |
||
178 | * @return void |
||
179 | */ |
||
180 | public function impressionsMaxCanBeSetTest() |
||
186 | |||
187 | /** |
||
188 | * Test if clicksmax can be set |
||
189 | * |
||
190 | * @test |
||
191 | * @return void |
||
192 | */ |
||
193 | public function clicksMaxCanBeSetTest() |
||
199 | |||
200 | /** |
||
201 | * Test if impressions can be set |
||
202 | * |
||
203 | * @test |
||
204 | * @return void |
||
205 | */ |
||
206 | public function impressionsCanBeSetTest() |
||
212 | |||
213 | /** |
||
214 | * Test if clicks can be set |
||
215 | * |
||
216 | * @test |
||
217 | * @return void |
||
218 | */ |
||
219 | public function clicksCanBeSetTest() |
||
225 | |||
226 | /** |
||
227 | * Test if recursive flag can be set |
||
228 | * |
||
229 | * @test |
||
230 | * @return void |
||
231 | */ |
||
232 | public function recursiveCanBeSet() |
||
237 | |||
238 | /** |
||
239 | * @test |
||
240 | */ |
||
241 | public function getCategoryReturnsInitialValueForCategory() |
||
249 | |||
250 | /** |
||
251 | * @test |
||
252 | */ |
||
253 | public function setCategoryForObjectStorageContainingCategorySetsCategory() |
||
261 | |||
262 | /** |
||
263 | * @test |
||
264 | */ |
||
265 | View Code Duplication | public function addCategoryToObjectStorageHoldingCategory() |
|
273 | |||
274 | /** |
||
275 | * @test |
||
276 | */ |
||
277 | View Code Duplication | public function removeCategoryFromObjectStorageHoldingCategory() |
|
285 | |||
286 | /** |
||
287 | * @test |
||
288 | */ |
||
289 | public function getExcludePagesReturnsInitialValueForExcudePages() |
||
297 | |||
298 | /** |
||
299 | * @test |
||
300 | */ |
||
301 | public function setExcludePagesForObjectStorageContainingExcludePagesSetsExcludePages() |
||
309 | |||
310 | /** |
||
311 | * @test |
||
312 | */ |
||
313 | View Code Duplication | public function addExludePagesToObjectStorageHoldingExcludePages() |
|
321 | |||
322 | /** |
||
323 | * @test |
||
324 | */ |
||
325 | View Code Duplication | public function removeExludePagesFromObjectStorageHoldingExcludePages() |
|
333 | |||
334 | /** |
||
335 | * @test |
||
336 | */ |
||
337 | public function getAssetsReturnsInitialValueForAsset() |
||
345 | |||
346 | /** |
||
347 | * @test |
||
348 | */ |
||
349 | public function setAssetForObjectStorageContainingAssetSetsAsset() |
||
357 | |||
358 | /** |
||
359 | * @test |
||
360 | */ |
||
361 | View Code Duplication | public function addAssetToObjectStorageHoldingAsses() |
|
369 | |||
370 | /** |
||
371 | * @test |
||
372 | */ |
||
373 | View Code Duplication | public function removeAssetFromObjectStorageHoldingAsset() |
|
381 | } |
||
382 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.