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 |
||
12 | class DropboxAdapter extends AbstractAdapter |
||
13 | { |
||
14 | use NotSupportingVisibilityTrait, ParseResponse; |
||
15 | |||
16 | /** @var \Srmklive\Dropbox\Client\DropboxClient */ |
||
17 | protected $client; |
||
18 | |||
19 | 19 | public function __construct(DropboxClient $client, $prefix = '') |
|
25 | |||
26 | /** |
||
27 | * {@inheritdoc} |
||
28 | */ |
||
29 | 1 | public function write($path, $contents, Config $config) |
|
33 | |||
34 | /** |
||
35 | * {@inheritdoc} |
||
36 | */ |
||
37 | 1 | public function writeStream($path, $resource, Config $config) |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 1 | public function update($path, $contents, Config $config) |
|
49 | |||
50 | /** |
||
51 | * {@inheritdoc} |
||
52 | */ |
||
53 | 1 | public function updateStream($path, $resource, Config $config) |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 2 | public function rename($path, $newPath) |
|
74 | |||
75 | /** |
||
76 | * {@inheritdoc} |
||
77 | */ |
||
78 | 2 | View Code Duplication | public function copy($path, $newpath) |
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 1 | public function delete($path) |
|
107 | |||
108 | /** |
||
109 | * {@inheritdoc} |
||
110 | */ |
||
111 | 1 | public function deleteDir($dirname) |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 1 | View Code Duplication | public function createDir($dirname, Config $config) |
131 | |||
132 | /** |
||
133 | * {@inheritdoc} |
||
134 | */ |
||
135 | 2 | public function has($path) |
|
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | 1 | public function read($path) |
|
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | 2 | View Code Duplication | public function readStream($path) |
173 | |||
174 | /** |
||
175 | * {@inheritdoc} |
||
176 | */ |
||
177 | 1 | public function listContents($directory = '', $recursive = false) |
|
193 | |||
194 | /** |
||
195 | * {@inheritdoc} |
||
196 | */ |
||
197 | 5 | View Code Duplication | public function getMetadata($path) |
211 | |||
212 | /** |
||
213 | * {@inheritdoc} |
||
214 | */ |
||
215 | 1 | public function getSize($path) |
|
219 | |||
220 | /** |
||
221 | * {@inheritdoc} |
||
222 | */ |
||
223 | public function getMimetype($path) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | 1 | public function getTimestamp($path) |
|
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function getTemporaryLink($path) |
||
249 | |||
250 | /** |
||
251 | * {@inheritdoc} |
||
252 | */ |
||
253 | public function getThumbnail($path, $format = 'jpeg', $size = 'w64h64') |
||
263 | |||
264 | /** |
||
265 | * {@inheritdoc} |
||
266 | */ |
||
267 | 18 | public function applyPathPrefix($path) |
|
273 | |||
274 | /** |
||
275 | * @return DropboxClient |
||
276 | */ |
||
277 | 1 | public function getClient() |
|
281 | |||
282 | /** |
||
283 | * @param string $path |
||
284 | * @param resource|string $contents |
||
285 | * @param string $mode |
||
286 | * |
||
287 | * @throws \Exception |
||
288 | * |
||
289 | * @return array|false file metadata |
||
290 | */ |
||
291 | 4 | View Code Duplication | protected function upload($path, $contents, $mode) |
305 | } |
||
306 |
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.