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 | * {@inheritdoc} |
||
59 | */ |
||
60 | public function write($path, $contents, Config $config) |
||
64 | |||
65 | /** |
||
66 | * {@inheritdoc} |
||
67 | */ |
||
68 | public function writeStream($path, $resource, Config $config) |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | public function update($path, $contents, Config $config) |
||
80 | |||
81 | /** |
||
82 | * {@inheritdoc} |
||
83 | */ |
||
84 | public function updateStream($path, $resource, Config $config) |
||
88 | |||
89 | /** |
||
90 | * {@inheritdoc} |
||
91 | */ |
||
92 | public function rename($path, $newpath) |
||
98 | |||
99 | public function copy($path, $newpath) |
||
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | public function delete($path) |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function deleteDir($dirname) |
||
141 | |||
142 | /** |
||
143 | * {@inheritdoc} |
||
144 | */ |
||
145 | public function createDir($dirname, Config $config) |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function has($path) |
||
171 | |||
172 | /** |
||
173 | * {@inheritdoc} |
||
174 | */ |
||
175 | View Code Duplication | public function read($path) |
|
186 | |||
187 | /** |
||
188 | * {@inheritdoc} |
||
189 | */ |
||
190 | View Code Duplication | public function readStream($path) |
|
200 | |||
201 | /** |
||
202 | * {@inheritdoc} |
||
203 | */ |
||
204 | public function listContents($directory = '', $recursive = false) |
||
239 | |||
240 | /** |
||
241 | * {@inheritdoc} |
||
242 | */ |
||
243 | public function getMetadata($path) |
||
252 | |||
253 | /** |
||
254 | * {@inheritdoc} |
||
255 | */ |
||
256 | public function getSize($path) |
||
260 | |||
261 | /** |
||
262 | * {@inheritdoc} |
||
263 | */ |
||
264 | public function getMimetype($path) |
||
268 | |||
269 | /** |
||
270 | * {@inheritdoc} |
||
271 | */ |
||
272 | public function getTimestamp($path) |
||
276 | |||
277 | /** |
||
278 | * Builds the normalized output array. |
||
279 | * |
||
280 | * @param string $path |
||
281 | * @param int $timestamp |
||
282 | * @param mixed $content |
||
283 | * |
||
284 | * @return array |
||
285 | */ |
||
286 | protected function normalize($path, $timestamp, $content = null) |
||
301 | |||
302 | /** |
||
303 | * Builds the normalized output array from a Blob object. |
||
304 | * |
||
305 | * @param string $path |
||
306 | * @param BlobProperties $properties |
||
307 | * |
||
308 | * @return array |
||
309 | */ |
||
310 | protected function normalizeBlobProperties($path, BlobProperties $properties) |
||
327 | |||
328 | /** |
||
329 | * Builds the normalized output array from a BlobPrefix object. |
||
330 | * |
||
331 | * @param BlobPrefix $blobPrefix |
||
332 | * |
||
333 | * @return array |
||
334 | */ |
||
335 | protected function normalizeBlobPrefix(BlobPrefix $blobPrefix) |
||
339 | |||
340 | /** |
||
341 | * Retrieves content streamed by Azure into a string. |
||
342 | * |
||
343 | * @param resource $resource |
||
344 | * |
||
345 | * @return string |
||
346 | */ |
||
347 | protected function streamContentsToString($resource) |
||
351 | |||
352 | /** |
||
353 | * Upload a file. |
||
354 | * |
||
355 | * @param string $path Path |
||
356 | * @param string|resource $contents Either a string or a stream. |
||
357 | * @param Config $config Config |
||
358 | * |
||
359 | * @return array |
||
360 | */ |
||
361 | protected function upload($path, $contents, Config $config) |
||
375 | |||
376 | /** |
||
377 | * Retrieve options from a Config instance. |
||
378 | * |
||
379 | * @param Config $config |
||
380 | * |
||
381 | * @return CreateBlobOptions |
||
382 | */ |
||
383 | protected function getOptionsFromConfig(Config $config) |
||
401 | } |
||
402 |
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: