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 |
||
11 | class BlobStorageSpec extends ObjectBehavior |
||
12 | { |
||
13 | /** |
||
14 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
15 | */ |
||
16 | public function let($blobProxyFactory) |
||
20 | |||
21 | public function it_should_be_initializable() |
||
27 | |||
28 | /** |
||
29 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
30 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
31 | * @param \MicrosoftAzure\Storage\Blob\Models\GetBlobResult $getBlobResult |
||
32 | */ |
||
33 | public function it_should_read_file($blobProxyFactory, $blobProxy, $getBlobResult) |
||
53 | |||
54 | /** |
||
55 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
56 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
57 | */ |
||
58 | View Code Duplication | public function it_should_return_false_when_cannot_read($blobProxyFactory, $blobProxy) |
|
72 | |||
73 | /** |
||
74 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
75 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
76 | */ |
||
77 | View Code Duplication | public function it_should_not_mask_exception_when_read($blobProxyFactory, $blobProxy) |
|
91 | |||
92 | /** |
||
93 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
94 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
95 | */ |
||
96 | View Code Duplication | public function it_should_rename_file($blobProxyFactory, $blobProxy) |
|
113 | |||
114 | /** |
||
115 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
116 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
117 | */ |
||
118 | View Code Duplication | public function it_should_return_false_when_cannot_rename($blobProxyFactory, $blobProxy) |
|
132 | |||
133 | /** |
||
134 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
135 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
136 | */ |
||
137 | View Code Duplication | public function it_should_not_mask_exception_when_rename($blobProxyFactory, $blobProxy) |
|
151 | |||
152 | /** |
||
153 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
154 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
155 | */ |
||
156 | View Code Duplication | public function it_should_write_file($blobProxyFactory, $blobProxy) |
|
169 | |||
170 | /** |
||
171 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
172 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
173 | */ |
||
174 | View Code Duplication | public function it_should_return_false_when_cannot_write($blobProxyFactory, $blobProxy) |
|
187 | |||
188 | /** |
||
189 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
190 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
191 | */ |
||
192 | View Code Duplication | public function it_should_not_mask_exception_when_write($blobProxyFactory, $blobProxy) |
|
205 | |||
206 | /** |
||
207 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
208 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
209 | * @param \MicrosoftAzure\Storage\Blob\Models\GetBlobPropertiesResult $getBlobPropertiesResult |
||
210 | * @param \MicrosoftAzure\Storage\Blob\Models\BlobProperties $blobProperties |
||
211 | */ |
||
212 | public function it_should_get_file_mtime($blobProxyFactory, $blobProxy, $getBlobPropertiesResult, $blobProperties) |
||
236 | |||
237 | /** |
||
238 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
239 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
240 | */ |
||
241 | public function it_should_return_false_when_cannot_mtime($blobProxyFactory, $blobProxy) |
||
255 | |||
256 | /** |
||
257 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
258 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
259 | */ |
||
260 | View Code Duplication | public function it_should_not_mask_exception_when_get_mtime($blobProxyFactory, $blobProxy) |
|
274 | |||
275 | /** |
||
276 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
277 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
278 | */ |
||
279 | public function it_should_delete_file($blobProxyFactory, $blobProxy) |
||
292 | |||
293 | /** |
||
294 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
295 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
296 | */ |
||
297 | View Code Duplication | public function it_should_return_false_when_cannot_delete_file($blobProxyFactory, $blobProxy) |
|
311 | |||
312 | /** |
||
313 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
314 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
315 | */ |
||
316 | View Code Duplication | public function it_should_not_mask_exception_when_delete($blobProxyFactory, $blobProxy) |
|
330 | |||
331 | /** |
||
332 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
333 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
334 | * @param \MicrosoftAzure\Storage\Blob\Models\ListBlobsResult $listBlobResult |
||
335 | */ |
||
336 | public function it_should_get_keys($blobProxyFactory, $blobProxy, $listBlobResult) |
||
363 | |||
364 | /** |
||
365 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
366 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
367 | */ |
||
368 | public function it_should_not_mask_exception_when_get_keys($blobProxyFactory, $blobProxy) |
||
382 | |||
383 | /** |
||
384 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
385 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
386 | */ |
||
387 | public function it_should_create_container($blobProxyFactory, $blobProxy) |
||
400 | |||
401 | /** |
||
402 | * @param \Gaufrette\Adapter\Azure\BlobProxyFactoryInterface $blobProxyFactory |
||
403 | * @param \MicrosoftAzure\Storage\Blob\Internal\IBlob $blobProxy |
||
404 | */ |
||
405 | View Code Duplication | public function it_should_fail_when_cannot_create_container($blobProxyFactory, $blobProxy) |
|
419 | |||
420 | } |
||
421 |
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.