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 | */ |
||
| 49 | public function __construct(IBlob $azureClient, $container, $prefix = null) |
||
| 55 | |||
| 56 | /** |
||
| 57 | * {@inheritdoc} |
||
| 58 | */ |
||
| 59 | public function write($path, $contents, Config $config) |
||
| 63 | |||
| 64 | /** |
||
| 65 | * {@inheritdoc} |
||
| 66 | */ |
||
| 67 | public function writeStream($path, $resource, Config $config) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * {@inheritdoc} |
||
| 74 | */ |
||
| 75 | public function update($path, $contents, Config $config) |
||
| 79 | |||
| 80 | /** |
||
| 81 | * {@inheritdoc} |
||
| 82 | */ |
||
| 83 | public function updateStream($path, $resource, Config $config) |
||
| 87 | |||
| 88 | /** |
||
| 89 | * {@inheritdoc} |
||
| 90 | */ |
||
| 91 | public function rename($path, $newpath) |
||
| 97 | |||
| 98 | public function copy($path, $newpath) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * {@inheritdoc} |
||
| 110 | */ |
||
| 111 | public function delete($path) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * {@inheritdoc} |
||
| 122 | */ |
||
| 123 | public function deleteDir($dirname) |
||
| 140 | |||
| 141 | /** |
||
| 142 | * {@inheritdoc} |
||
| 143 | */ |
||
| 144 | public function createDir($dirname, Config $config) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * {@inheritdoc} |
||
| 153 | */ |
||
| 154 | public function has($path) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * {@inheritdoc} |
||
| 173 | */ |
||
| 174 | View Code Duplication | public function read($path) |
|
| 185 | |||
| 186 | /** |
||
| 187 | * {@inheritdoc} |
||
| 188 | */ |
||
| 189 | View Code Duplication | public function readStream($path) |
|
| 199 | |||
| 200 | /** |
||
| 201 | * {@inheritdoc} |
||
| 202 | */ |
||
| 203 | public function listContents($directory = '', $recursive = false) |
||
| 235 | |||
| 236 | /** |
||
| 237 | * {@inheritdoc} |
||
| 238 | */ |
||
| 239 | public function getMetadata($path) |
||
| 248 | |||
| 249 | /** |
||
| 250 | * {@inheritdoc} |
||
| 251 | */ |
||
| 252 | public function getSize($path) |
||
| 256 | |||
| 257 | /** |
||
| 258 | * {@inheritdoc} |
||
| 259 | */ |
||
| 260 | public function getMimetype($path) |
||
| 264 | |||
| 265 | /** |
||
| 266 | * {@inheritdoc} |
||
| 267 | */ |
||
| 268 | public function getTimestamp($path) |
||
| 272 | |||
| 273 | /** |
||
| 274 | * Builds the normalized output array. |
||
| 275 | * |
||
| 276 | * @param string $path |
||
| 277 | * @param int $timestamp |
||
| 278 | * @param mixed $content |
||
| 279 | * |
||
| 280 | * @return array |
||
| 281 | */ |
||
| 282 | protected function normalize($path, $timestamp, $content = null) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Builds the normalized output array from a Blob object. |
||
| 300 | * |
||
| 301 | * @param string $path |
||
| 302 | * @param BlobProperties $properties |
||
| 303 | * |
||
| 304 | * @return array |
||
| 305 | */ |
||
| 306 | protected function normalizeBlobProperties($path, BlobProperties $properties) |
||
| 323 | |||
| 324 | /** |
||
| 325 | * Builds the normalized output array from a BlobPrefix object. |
||
| 326 | * |
||
| 327 | * @param BlobPrefix $blobPrefix |
||
| 328 | * |
||
| 329 | * @return array |
||
| 330 | */ |
||
| 331 | protected function normalizeBlobPrefix(BlobPrefix $blobPrefix) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Retrieves content streamed by Azure into a string. |
||
| 338 | * |
||
| 339 | * @param resource $resource |
||
| 340 | * |
||
| 341 | * @return string |
||
| 342 | */ |
||
| 343 | protected function streamContentsToString($resource) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Upload a file. |
||
| 350 | * |
||
| 351 | * @param string $path Path |
||
| 352 | * @param string|resource $contents Either a string or a stream. |
||
| 353 | * @param Config $config Config |
||
| 354 | * |
||
| 355 | * @return array |
||
| 356 | */ |
||
| 357 | protected function upload($path, $contents, Config $config) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Retrieve options from a Config instance. |
||
| 369 | * |
||
| 370 | * @param Config $config |
||
| 371 | * |
||
| 372 | * @return CreateBlobOptions |
||
| 373 | */ |
||
| 374 | protected function getOptionsFromConfig(Config $config) |
||
| 392 | } |
||
| 393 |
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: