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, ResourcesSupporter, ListKeysAware |
||
| 17 | { |
||
| 18 | protected $storageClient; |
||
| 19 | protected $bucket; |
||
| 20 | protected $bucketValidated; |
||
| 21 | protected $options = array(); |
||
| 22 | protected $metadata = array(); |
||
| 23 | protected $resources = 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()) |
||
| 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 = null) |
||
| 72 | |||
| 73 | protected function isBucket() |
||
| 84 | |||
| 85 | public function setBucket($name) |
||
| 91 | |||
| 92 | public function getBucket() |
||
| 96 | |||
| 97 | /** |
||
| 98 | * {@inheritdoc} |
||
| 99 | */ |
||
| 100 | View Code Duplication | public function read($key) |
|
| 108 | |||
| 109 | /** |
||
| 110 | * {@inheritdoc} |
||
| 111 | */ |
||
| 112 | public function write($key, $content) |
||
| 137 | |||
| 138 | /** |
||
| 139 | * {@inheritdoc} |
||
| 140 | */ |
||
| 141 | public function exists($key) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * {@inheritdoc} |
||
| 150 | */ |
||
| 151 | public function isDirectory($key) |
||
| 155 | |||
| 156 | /** |
||
| 157 | * {@inheritdoc} |
||
| 158 | */ |
||
| 159 | public function listKeys($prefix = null) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | public function keys() |
||
| 179 | |||
| 180 | /** |
||
| 181 | * {@inheritdoc} |
||
| 182 | */ |
||
| 183 | View Code Duplication | public function mtime($key) |
|
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | public function delete($key) |
||
| 203 | |||
| 204 | /** |
||
| 205 | * {@inheritdoc} |
||
| 206 | */ |
||
| 207 | public function rename($sourceKey, $targetKey) |
||
| 237 | |||
| 238 | /** |
||
| 239 | * {@inheritdoc} |
||
| 240 | */ |
||
| 241 | public function setMetadata($key, $metadata) |
||
| 245 | |||
| 246 | /** |
||
| 247 | * {@inheritdoc} |
||
| 248 | */ |
||
| 249 | public function getMetadata($key) |
||
| 262 | |||
| 263 | /** |
||
| 264 | * {@inheritdoc} |
||
| 265 | */ |
||
| 266 | public function setResources($key, $data) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * {@inheritdoc} |
||
| 273 | */ |
||
| 274 | public function getResources($key) |
||
| 279 | |||
| 280 | /** |
||
| 281 | * {@inheritdoc} |
||
| 282 | */ |
||
| 283 | public function getResourceByName($key, $resourceName) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * Sets ACL and metadata information. |
||
| 291 | * |
||
| 292 | * @param string $key |
||
| 293 | * @param array $options Can contain "acl" and/or "metadata" arrays. |
||
| 294 | * @return boolean |
||
| 295 | */ |
||
| 296 | protected function updateKeyProperties($key, $options = array()) |
||
| 324 | } |
||
| 325 |
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
$italyis not defined by the methodfinale(...).The most likely cause is that the parameter was removed, but the annotation was not.