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 |
||
17 | class GoogleCloudClientStorage implements Adapter, MetadataSupporter, ResourcesSupporter, ListKeysAware { |
||
18 | |||
19 | protected $storageClient; |
||
20 | protected $bucket; |
||
21 | protected $bucketValidated; |
||
22 | protected $options = array(); |
||
23 | protected $metadata = array(); |
||
24 | protected $resources = array(); |
||
25 | |||
26 | /** |
||
27 | * @param Google\Cloud\Storage\StorageClient $service Authenticated storage client class |
||
|
|||
28 | * @param string $bucketName Name of the bucket |
||
29 | * @param array $options Options are: "directory" and "acl" (see https://cloud.google.com/storage/docs/access-control/lists) |
||
30 | */ |
||
31 | public function __construct(\Google\Cloud\Storage\StorageClient $storageClient, $bucketName, $options = array()) |
||
43 | |||
44 | /** |
||
45 | * Get adapter options |
||
46 | * |
||
47 | * @return array |
||
48 | */ |
||
49 | public function getOptions() |
||
53 | |||
54 | /** |
||
55 | * Set adapter options |
||
56 | * |
||
57 | * @param array $options |
||
58 | */ |
||
59 | public function setOptions($options) |
||
63 | |||
64 | protected function computePath($key) |
||
76 | |||
77 | protected function isBucket() |
||
88 | |||
89 | public function setBucket($name) |
||
95 | |||
96 | public function getBucket() |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | View Code Duplication | public function read($key) |
|
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | public function write($key, $content) |
||
142 | |||
143 | /** |
||
144 | * {@inheritdoc} |
||
145 | */ |
||
146 | public function exists($key) |
||
156 | |||
157 | /** |
||
158 | * {@inheritdoc} |
||
159 | */ |
||
160 | public function isDirectory($key) |
||
168 | |||
169 | /** |
||
170 | * {@inheritdoc} |
||
171 | */ |
||
172 | public function listKeys($prefix = null) |
||
189 | |||
190 | /** |
||
191 | * {@inheritdoc} |
||
192 | */ |
||
193 | public function keys() |
||
197 | |||
198 | /** |
||
199 | * {@inheritdoc} |
||
200 | */ |
||
201 | View Code Duplication | public function mtime($key) |
|
209 | |||
210 | /** |
||
211 | * {@inheritdoc} |
||
212 | */ |
||
213 | public function delete($key) |
||
220 | |||
221 | /** |
||
222 | * {@inheritdoc} |
||
223 | */ |
||
224 | public function rename($sourceKey, $targetKey) |
||
256 | |||
257 | /** |
||
258 | * {@inheritdoc} |
||
259 | */ |
||
260 | public function setMetadata($key, $metadata) |
||
264 | |||
265 | /** |
||
266 | * {@inheritdoc} |
||
267 | */ |
||
268 | public function getMetadata($key) |
||
272 | |||
273 | /** |
||
274 | * {@inheritdoc} |
||
275 | */ |
||
276 | public function setResources($key, $data) |
||
280 | |||
281 | /** |
||
282 | * {@inheritdoc} |
||
283 | */ |
||
284 | public function getResources($key) |
||
288 | |||
289 | /** |
||
290 | * {@inheritdoc} |
||
291 | */ |
||
292 | public function getResourceByName($key, $resourceName) |
||
296 | |||
297 | /** |
||
298 | * Sets ACL and metadata information. |
||
299 | * |
||
300 | * @param string $key |
||
301 | * @param array $options Can contain "acl" and/or "metadata" arrays. |
||
302 | * @return boolean |
||
303 | */ |
||
304 | protected function updateKeyProperties($key, $options = array()) |
||
332 | } |
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.