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 |
||
| 18 | class AzureAdapter extends AbstractAdapter |
||
| 19 | { |
||
| 20 | use NotSupportingVisibilityTrait; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * @var string |
||
| 24 | */ |
||
| 25 | protected $container; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var IBlob |
||
| 29 | */ |
||
| 30 | protected $client; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string[] |
||
| 34 | */ |
||
| 35 | protected static $metaOptions = [ |
||
| 36 | 'CacheControl', |
||
| 37 | 'ContentType', |
||
| 38 | 'Metadata', |
||
| 39 | 'ContentLanguage', |
||
| 40 | 'ContentEncoding', |
||
| 41 | ]; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Constructor. |
||
| 45 | * |
||
| 46 | * @param IBlob $azureClient |
||
| 47 | * @param string $container |
||
| 48 | * @param string $prefix |
||
| 49 | */ |
||
| 50 | public function __construct(IBlob $azureClient, $container, $prefix = null) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Get the Azure client instance. |
||
| 59 | * |
||
| 60 | * @return IBlob |
||
| 61 | */ |
||
| 62 | public function getClient() |
||
| 66 | |||
| 67 | /** |
||
| 68 | * Get the Azure container. |
||
| 69 | * |
||
| 70 | * @return string |
||
| 71 | */ |
||
| 72 | public function getContainer() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * {@inheritdoc} |
||
| 79 | */ |
||
| 80 | public function write($path, $contents, Config $config) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * {@inheritdoc} |
||
| 87 | */ |
||
| 88 | public function writeStream($path, $resource, Config $config) |
||
| 92 | |||
| 93 | /** |
||
| 94 | * {@inheritdoc} |
||
| 95 | */ |
||
| 96 | public function update($path, $contents, Config $config) |
||
| 100 | |||
| 101 | /** |
||
| 102 | * {@inheritdoc} |
||
| 103 | */ |
||
| 104 | public function updateStream($path, $resource, Config $config) |
||
| 108 | |||
| 109 | /** |
||
| 110 | * {@inheritdoc} |
||
| 111 | */ |
||
| 112 | public function rename($path, $newpath) |
||
| 118 | |||
| 119 | public function copy($path, $newpath) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * {@inheritdoc} |
||
| 131 | */ |
||
| 132 | public function delete($path) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * {@inheritdoc} |
||
| 143 | */ |
||
| 144 | public function deleteDir($dirname) |
||
| 161 | |||
| 162 | /** |
||
| 163 | * {@inheritdoc} |
||
| 164 | */ |
||
| 165 | public function createDir($dirname, Config $config) |
||
| 171 | |||
| 172 | /** |
||
| 173 | * {@inheritdoc} |
||
| 174 | */ |
||
| 175 | public function has($path) |
||
| 191 | |||
| 192 | /** |
||
| 193 | * {@inheritdoc} |
||
| 194 | */ |
||
| 195 | View Code Duplication | public function read($path) |
|
| 206 | |||
| 207 | /** |
||
| 208 | * {@inheritdoc} |
||
| 209 | */ |
||
| 210 | View Code Duplication | public function readStream($path) |
|
| 220 | |||
| 221 | /** |
||
| 222 | * {@inheritdoc} |
||
| 223 | */ |
||
| 224 | public function listContents($directory = '', $recursive = false) |
||
| 259 | |||
| 260 | /** |
||
| 261 | * {@inheritdoc} |
||
| 262 | */ |
||
| 263 | public function getMetadata($path) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * {@inheritdoc} |
||
| 275 | */ |
||
| 276 | public function getSize($path) |
||
| 280 | |||
| 281 | /** |
||
| 282 | * {@inheritdoc} |
||
| 283 | */ |
||
| 284 | public function getMimetype($path) |
||
| 288 | |||
| 289 | /** |
||
| 290 | * {@inheritdoc} |
||
| 291 | */ |
||
| 292 | public function getTimestamp($path) |
||
| 296 | |||
| 297 | /** |
||
| 298 | * Builds the normalized output array. |
||
| 299 | * |
||
| 300 | * @param string $path |
||
| 301 | * @param int $timestamp |
||
| 302 | * @param mixed $content |
||
| 303 | * |
||
| 304 | * @return array |
||
| 305 | */ |
||
| 306 | protected function normalize($path, $timestamp, $content = null) |
||
| 321 | |||
| 322 | /** |
||
| 323 | * Builds the normalized output array from a Blob object. |
||
| 324 | * |
||
| 325 | * @param string $path |
||
| 326 | * @param BlobProperties $properties |
||
| 327 | * |
||
| 328 | * @return array |
||
| 329 | */ |
||
| 330 | protected function normalizeBlobProperties($path, BlobProperties $properties) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Builds the normalized output array from a BlobPrefix object. |
||
| 350 | * |
||
| 351 | * @param BlobPrefix $blobPrefix |
||
| 352 | * |
||
| 353 | * @return array |
||
| 354 | */ |
||
| 355 | protected function normalizeBlobPrefix(BlobPrefix $blobPrefix) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * Retrieves content streamed by Azure into a string. |
||
| 362 | * |
||
| 363 | * @param resource $resource |
||
| 364 | * |
||
| 365 | * @return string |
||
| 366 | */ |
||
| 367 | protected function streamContentsToString($resource) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Upload a file. |
||
| 374 | * |
||
| 375 | * @param string $path Path |
||
| 376 | * @param string|resource $contents Either a string or a stream. |
||
| 377 | * @param Config $config Config |
||
| 378 | * |
||
| 379 | * @return array |
||
| 380 | */ |
||
| 381 | protected function upload($path, $contents, Config $config) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * Retrieve options from a Config instance. |
||
| 398 | * |
||
| 399 | * @param Config $config |
||
| 400 | * |
||
| 401 | * @return CreateBlobOptions |
||
| 402 | */ |
||
| 403 | protected function getOptionsFromConfig(Config $config) |
||
| 421 | } |
||
| 422 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: