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 |
||
16 | class GoogleCloudClientStorage implements Adapter, MetadataSupporter, ResourceSupporter, ListKeysAware { |
||
17 | |||
18 | protected $storageClient; |
||
19 | protected $bucket; |
||
20 | protected $bucketValidated; |
||
21 | protected $options = array(); |
||
22 | protected $metadata = array(); |
||
23 | protected $resource = array(); |
||
24 | |||
25 | /** |
||
26 | * @param Google\Cloud\Storage\StorageClient $service Authenticated storage client class |
||
|
|||
27 | * @param string $bucketName Name of the bucket |
||
28 | * @param array $options Options are: "directory" and "acl" (see https://cloud.google.com/storage/docs/access-control/lists) |
||
29 | */ |
||
30 | public function __construct(\Google\Cloud\Storage\StorageClient $storageClient, $bucketName, $options = array()) |
||
42 | |||
43 | /** |
||
44 | * Get adapter options |
||
45 | * |
||
46 | * @return array |
||
47 | */ |
||
48 | public function getOptions() |
||
52 | |||
53 | /** |
||
54 | * Set adapter options |
||
55 | * |
||
56 | * @param array $options |
||
57 | */ |
||
58 | public function setOptions($options) |
||
62 | |||
63 | protected function computePath($key) |
||
75 | |||
76 | protected function isBucket() |
||
87 | |||
88 | public function setBucket($name) |
||
94 | |||
95 | public function getBucket() |
||
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | View Code Duplication | public function read($key) |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | public function write($key, $content) |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function exists($key) |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | public function isDirectory($key) |
||
167 | |||
168 | /** |
||
169 | * {@inheritdoc} |
||
170 | */ |
||
171 | public function listKeys($prefix = null) |
||
188 | |||
189 | /** |
||
190 | * {@inheritdoc} |
||
191 | */ |
||
192 | public function keys() |
||
196 | |||
197 | /** |
||
198 | * {@inheritdoc} |
||
199 | */ |
||
200 | View Code Duplication | public function mtime($key) |
|
208 | |||
209 | /** |
||
210 | * {@inheritdoc} |
||
211 | */ |
||
212 | public function delete($key) |
||
218 | |||
219 | /** |
||
220 | * {@inheritdoc} |
||
221 | */ |
||
222 | public function rename($sourceKey, $targetKey) |
||
227 | |||
228 | /** |
||
229 | * {@inheritdoc} |
||
230 | */ |
||
231 | public function setMetadata($key, $metadata) |
||
235 | |||
236 | /** |
||
237 | * {@inheritdoc} |
||
238 | */ |
||
239 | public function getMetadata($key) |
||
243 | |||
244 | /** |
||
245 | * {@inheritdoc} |
||
246 | */ |
||
247 | public function setResource($key, $data) |
||
251 | |||
252 | /** |
||
253 | * {@inheritdoc} |
||
254 | */ |
||
255 | public function getResource($key, $name = null) |
||
268 | } |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.