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 DropboxAdapter extends AbstractAdapter |
||
14 | { |
||
15 | use NotSupportingVisibilityTrait, ParseResponse; |
||
16 | |||
17 | /** @var \Srmklive\Dropbox\Client\DropboxClient */ |
||
18 | protected $client; |
||
19 | |||
20 | 19 | public function __construct(DropboxClient $client, $prefix = '') |
|
26 | |||
27 | /** |
||
28 | * {@inheritdoc} |
||
29 | */ |
||
30 | 1 | public function write($path, $contents, Config $config) |
|
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 1 | public function writeStream($path, $resource, Config $config) |
|
42 | |||
43 | /** |
||
44 | * {@inheritdoc} |
||
45 | */ |
||
46 | 1 | public function update($path, $contents, Config $config) |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 1 | public function updateStream($path, $resource, Config $config) |
|
58 | |||
59 | /** |
||
60 | * {@inheritdoc} |
||
61 | */ |
||
62 | 2 | public function rename($path, $newPath) |
|
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 2 | View Code Duplication | public function copy($path, $newpath) |
92 | |||
93 | /** |
||
94 | * {@inheritdoc} |
||
95 | */ |
||
96 | 1 | public function delete($path) |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 1 | public function deleteDir($dirname) |
|
116 | |||
117 | /** |
||
118 | * {@inheritdoc} |
||
119 | */ |
||
120 | 1 | View Code Duplication | public function createDir($dirname, Config $config) |
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | 2 | public function has($path) |
|
140 | |||
141 | /** |
||
142 | * {@inheritdoc} |
||
143 | */ |
||
144 | 1 | public function read($path) |
|
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | 2 | View Code Duplication | public function readStream($path) |
172 | |||
173 | /** |
||
174 | * {@inheritdoc} |
||
175 | */ |
||
176 | 1 | public function listContents($directory = '', $recursive = false) |
|
192 | |||
193 | /** |
||
194 | * {@inheritdoc} |
||
195 | */ |
||
196 | 5 | View Code Duplication | public function getMetadata($path) |
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | 1 | public function getSize($path) |
|
216 | |||
217 | /** |
||
218 | * {@inheritdoc} |
||
219 | */ |
||
220 | public function getMimetype($path) |
||
224 | |||
225 | /** |
||
226 | * {@inheritdoc} |
||
227 | */ |
||
228 | 1 | public function getTimestamp($path) |
|
232 | |||
233 | public function getTemporaryLink($path) |
||
237 | |||
238 | public function getThumbnail($path, $format = 'jpeg', $size = 'w64h64') |
||
242 | |||
243 | /** |
||
244 | * {@inheritdoc} |
||
245 | */ |
||
246 | 18 | public function applyPathPrefix($path) |
|
252 | |||
253 | 1 | public function getClient() |
|
257 | |||
258 | /** |
||
259 | * @param string $path |
||
260 | * @param resource|string $contents |
||
261 | * @param string $mode |
||
262 | * |
||
263 | * @return array|false file metadata |
||
264 | */ |
||
265 | 4 | View Code Duplication | protected function upload($path, $contents, $mode) |
277 | } |
||
278 |
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.
In this case you can add the
@ignore
PhpDoc annotation to the duplicate definition and it will be ignored.