Complex classes like QiniuAdapter often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use QiniuAdapter, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 19 | class QiniuAdapter extends AbstractAdapter |
||
| 20 | { |
||
| 21 | use NotSupportingVisibilityTrait; |
||
| 22 | |||
| 23 | protected $accessKey; |
||
| 24 | protected $secretKey; |
||
| 25 | protected $bucket; |
||
| 26 | protected $domain; |
||
| 27 | |||
| 28 | protected $authManager; |
||
| 29 | protected $uploadManager; |
||
| 30 | protected $bucketManager; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * QiniuAdapter constructor. |
||
| 34 | * |
||
| 35 | * @param string $accessKey |
||
| 36 | * @param string $secretKey |
||
| 37 | * @param string $bucket |
||
| 38 | * @param string $domain |
||
| 39 | */ |
||
| 40 | 1 | public function __construct($accessKey, $secretKey, $bucket, $domain) |
|
| 47 | |||
| 48 | /** |
||
| 49 | * Write a new file. |
||
| 50 | * |
||
| 51 | * @param string $path |
||
| 52 | * @param string $contents |
||
| 53 | * @param Config $config Config object |
||
| 54 | * |
||
| 55 | * @return array|false false on failure file meta data on success |
||
| 56 | */ |
||
| 57 | 1 | public function write($path, $contents, Config $config) |
|
| 78 | |||
| 79 | /** |
||
| 80 | * Write a new file using a stream. |
||
| 81 | 1 | * |
|
| 82 | * @param string $path |
||
| 83 | 1 | * @param resource $resource |
|
| 84 | * @param Config $config Config object |
||
| 85 | 1 | * |
|
| 86 | 1 | * @return array|false false on failure file meta data on success |
|
| 87 | 1 | */ |
|
| 88 | public function writeStream($path, $resource, Config $config) |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Update a file. |
||
| 107 | 1 | * |
|
| 108 | * @param string $path |
||
| 109 | 1 | * @param string $contents |
|
| 110 | * @param Config $config Config object |
||
| 111 | 1 | * |
|
| 112 | * @return array|false false on failure file meta data on success |
||
| 113 | */ |
||
| 114 | public function update($path, $contents, Config $config) |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Update a file using a stream. |
||
| 123 | 1 | * |
|
| 124 | * @param string $path |
||
| 125 | 1 | * @param resource $resource |
|
| 126 | * @param Config $config Config object |
||
| 127 | 1 | * |
|
| 128 | * @return array|false false on failure file meta data on success |
||
| 129 | */ |
||
| 130 | public function updateStream($path, $resource, Config $config) |
||
| 136 | |||
| 137 | /** |
||
| 138 | 1 | * Rename a file. |
|
| 139 | * |
||
| 140 | 1 | * @param string $path |
|
| 141 | * @param string $newpath |
||
| 142 | 1 | * |
|
| 143 | * @return bool |
||
| 144 | */ |
||
| 145 | public function rename($path, $newpath) |
||
| 151 | |||
| 152 | /** |
||
| 153 | 1 | * Copy a file. |
|
| 154 | * |
||
| 155 | 1 | * @param string $path |
|
| 156 | * @param string $newpath |
||
| 157 | 1 | * |
|
| 158 | * @return bool |
||
| 159 | */ |
||
| 160 | public function copy($path, $newpath) |
||
| 166 | |||
| 167 | 1 | /** |
|
| 168 | * Delete a file. |
||
| 169 | 1 | * |
|
| 170 | * @param string $path |
||
| 171 | 1 | * |
|
| 172 | * @return bool |
||
| 173 | */ |
||
| 174 | public function delete($path) |
||
| 180 | |||
| 181 | 1 | /** |
|
| 182 | * Delete a directory. |
||
| 183 | 1 | * |
|
| 184 | * @param string $dirname |
||
| 185 | * |
||
| 186 | * @return bool |
||
| 187 | */ |
||
| 188 | public function deleteDir($dirname) |
||
| 192 | |||
| 193 | /** |
||
| 194 | 1 | * Create a directory. |
|
| 195 | * |
||
| 196 | 1 | * @param string $dirname directory name |
|
| 197 | * @param Config $config |
||
| 198 | * |
||
| 199 | * @return array|false |
||
| 200 | */ |
||
| 201 | public function createDir($dirname, Config $config) |
||
| 205 | |||
| 206 | 1 | /** |
|
| 207 | * Check whether a file exists. |
||
| 208 | 1 | * |
|
| 209 | * @param string $path |
||
| 210 | 1 | * |
|
| 211 | * @return array|bool|null |
||
| 212 | */ |
||
| 213 | public function has($path) |
||
| 219 | |||
| 220 | 1 | /** |
|
| 221 | * Get resource url. |
||
| 222 | 1 | * |
|
| 223 | * @param string $path |
||
| 224 | * |
||
| 225 | * @return string |
||
| 226 | */ |
||
| 227 | public function getUrl($path) |
||
| 231 | |||
| 232 | 1 | /** |
|
| 233 | * Read a file. |
||
| 234 | 1 | * |
|
| 235 | * @param string $path |
||
| 236 | 1 | * |
|
| 237 | * @return array|false |
||
| 238 | */ |
||
| 239 | public function read($path) |
||
| 245 | |||
| 246 | 1 | /** |
|
| 247 | * Read a file as a stream. |
||
| 248 | 1 | * |
|
| 249 | 1 | * @param string $path |
|
| 250 | * |
||
| 251 | 1 | * @return array|false |
|
| 252 | */ |
||
| 253 | public function readStream($path) |
||
| 263 | |||
| 264 | /** |
||
| 265 | 1 | * List contents of a directory. |
|
| 266 | * |
||
| 267 | 1 | * @param string $directory |
|
| 268 | * @param bool $recursive |
||
| 269 | 1 | * |
|
| 270 | * @return array |
||
| 271 | 1 | */ |
|
| 272 | 1 | public function listContents($directory = '', $recursive = false) |
|
| 284 | |||
| 285 | 1 | /** |
|
| 286 | * Get all the meta data of a file or directory. |
||
| 287 | 1 | * |
|
| 288 | 1 | * @param string $path |
|
| 289 | * |
||
| 290 | 1 | * @return array|false |
|
| 291 | */ |
||
| 292 | public function getMetadata($path) |
||
| 299 | |||
| 300 | 1 | /** |
|
| 301 | * Get the size of a file. |
||
| 302 | 1 | * |
|
| 303 | * @param string $path |
||
| 304 | * |
||
| 305 | * @return array|false |
||
| 306 | */ |
||
| 307 | public function getSize($path) |
||
| 311 | |||
| 312 | 1 | /** |
|
| 313 | * Fetch url to bucket |
||
| 314 | 1 | * |
|
| 315 | * @param string $path |
||
| 316 | 1 | * @param string $url |
|
| 317 | 1 | * |
|
| 318 | * @return array|false |
||
| 319 | */ |
||
| 320 | 1 | public function fetch($path, $url) |
|
| 329 | |||
| 330 | 1 | /** |
|
| 331 | * Get the mimetype of a file. |
||
| 332 | 1 | * |
|
| 333 | * @param string $path |
||
| 334 | * |
||
| 335 | * @return array|false |
||
| 336 | */ |
||
| 337 | public function getMimetype($path) |
||
| 347 | |||
| 348 | /** |
||
| 349 | * Get the timestamp of a file. |
||
| 350 | * |
||
| 351 | * @param string $path |
||
| 352 | 1 | * |
|
| 353 | * @return array|false |
||
| 354 | 1 | */ |
|
| 355 | public function getTimestamp($path) |
||
| 359 | |||
| 360 | /** |
||
| 361 | * @param \Qiniu\Storage\BucketManager $manager |
||
| 362 | * |
||
| 363 | * @return $this |
||
| 364 | 1 | */ |
|
| 365 | public function setBucketManager(BucketManager $manager) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * @param \Qiniu\Storage\UploadManager $manager |
||
| 374 | 1 | * |
|
| 375 | * @return $this |
||
| 376 | 1 | */ |
|
| 377 | public function setUploadManager(UploadManager $manager) |
||
| 383 | |||
| 384 | 1 | /** |
|
| 385 | * @param \Qiniu\Auth $manager |
||
| 386 | * |
||
| 387 | * @return $this |
||
| 388 | */ |
||
| 389 | public function setAuthManager(Auth $manager) |
||
| 395 | |||
| 396 | /** |
||
| 397 | * @return \Qiniu\Storage\BucketManager |
||
| 398 | */ |
||
| 399 | public function getBucketManager() |
||
| 403 | 2 | ||
| 404 | 2 | /** |
|
| 405 | 2 | * @return \Qiniu\Auth |
|
| 406 | 2 | */ |
|
| 407 | 2 | public function getAuthManager() |
|
| 411 | |||
| 412 | /** |
||
| 413 | * @return \Qiniu\Storage\UploadManager |
||
| 414 | */ |
||
| 415 | 2 | public function getUploadManager() |
|
| 419 | 2 | ||
| 420 | /** |
||
| 421 | 2 | * @param array $stats |
|
| 422 | * |
||
| 423 | * @return array |
||
| 424 | */ |
||
| 425 | protected function normalizeFileInfo(array $stats) |
||
| 434 | |||
| 435 | /** |
||
| 436 | * @param string $domain |
||
| 437 | * |
||
| 438 | * @return string |
||
| 439 | */ |
||
| 440 | protected function normalizeHost($domain) |
||
| 448 | } |
||
| 449 |
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: