Complex classes like StorageManager 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 StorageManager, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class StorageManager |
||
| 15 | { |
||
| 16 | /** |
||
| 17 | * @var Storage |
||
| 18 | */ |
||
| 19 | protected $storage; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var ImagineFactory |
||
| 23 | */ |
||
| 24 | protected $imagineFactory; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * Construct |
||
| 28 | * |
||
| 29 | * @param Storage $storage |
||
| 30 | * @param ImagineFactory $imagineFactory |
||
| 31 | */ |
||
| 32 | public function __construct(Storage $storage, ImagineFactory $imagineFactory = null) |
||
| 37 | |||
| 38 | /** |
||
| 39 | * File Exists |
||
| 40 | * |
||
| 41 | * @param string $filename Path File |
||
| 42 | * |
||
| 43 | * @return bool |
||
| 44 | */ |
||
| 45 | public function exists($filename) |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Get Size |
||
| 57 | * |
||
| 58 | * @param string $filename Path File |
||
| 59 | * |
||
| 60 | * @return bool |
||
| 61 | */ |
||
| 62 | public function size($filename) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Get MimeType File |
||
| 74 | * |
||
| 75 | * @param string $filename Path File |
||
| 76 | * |
||
| 77 | * @return bool |
||
| 78 | */ |
||
| 79 | public function mimeType($filename) |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Path is Directory |
||
| 91 | * |
||
| 92 | * @param string $path Path Directory |
||
| 93 | * |
||
| 94 | * @return bool |
||
| 95 | */ |
||
| 96 | public function isDir($path) |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Is File |
||
| 109 | * |
||
| 110 | * @param string $filename Path File |
||
| 111 | * |
||
| 112 | * @return bool |
||
| 113 | */ |
||
| 114 | public function isFile($filename) |
||
| 118 | |||
| 119 | /** |
||
| 120 | * Get Meta Data |
||
| 121 | * |
||
| 122 | * @param string $filename Path File |
||
| 123 | * |
||
| 124 | * @return bool |
||
| 125 | */ |
||
| 126 | public function metaData($filename) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Read Content File |
||
| 138 | * |
||
| 139 | * @param string $filename Path File |
||
| 140 | * |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function readFile($filename) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Delete File |
||
| 150 | * |
||
| 151 | * @param string $filename Path File |
||
| 152 | * |
||
| 153 | * @return bool |
||
| 154 | */ |
||
| 155 | public function deleteFile($filename) |
||
| 163 | |||
| 164 | /** |
||
| 165 | * Delete Folder |
||
| 166 | * |
||
| 167 | * @param string $folder |
||
| 168 | * |
||
| 169 | * @return bool |
||
| 170 | */ |
||
| 171 | public function deleteFolder($folder) |
||
| 179 | |||
| 180 | /** |
||
| 181 | * Files in Folder |
||
| 182 | * |
||
| 183 | * @param string $path |
||
| 184 | * @param bool $recursive |
||
| 185 | * |
||
| 186 | * @return array |
||
| 187 | */ |
||
| 188 | public function files($path, $recursive = false) |
||
| 196 | |||
| 197 | /** |
||
| 198 | * UploadFile |
||
| 199 | * |
||
| 200 | * @param UploadedFile|string $file Uploaded File |
||
| 201 | * @param string $folder String Folder |
||
| 202 | * @param string $name String Name |
||
| 203 | * @param bool $override Boolean Over Ride |
||
| 204 | * @param array $config Array Config Upload |
||
| 205 | * |
||
| 206 | * @return bool |
||
| 207 | */ |
||
| 208 | public function uploadFile(UploadedFile $file, $folder = null, $name = null, $override = false, array $config = []) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * Upload Image |
||
| 223 | * |
||
| 224 | * @param UploadedFile $file Uploaded File |
||
| 225 | * @param string $folder String Folder |
||
| 226 | * @param string $name String Name |
||
| 227 | * @param array $options Array Options |
||
| 228 | * @param bool $override Boolean Over Ride |
||
| 229 | * @param array $config Array Config Upload |
||
| 230 | * |
||
| 231 | * @return bool |
||
| 232 | */ |
||
| 233 | public function uploadImage( |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Parse Filename |
||
| 282 | * |
||
| 283 | * @param UploadedFile|string $file Uploaded File |
||
| 284 | * @param string $name String Name |
||
| 285 | * @param string $folder String Folder |
||
| 286 | * @param bool $override Boolean Over Ride |
||
| 287 | * |
||
| 288 | * @return bool|array |
||
| 289 | */ |
||
| 290 | protected function parseFile($file, $folder = null, $name = null, $override = false) |
||
| 328 | |||
| 329 | /** |
||
| 330 | * Crop Image |
||
| 331 | * |
||
| 332 | * @param string $filename |
||
| 333 | * @param int $width |
||
| 334 | * @param int $height |
||
| 335 | * @param int $x |
||
| 336 | * @param int $y |
||
| 337 | * |
||
| 338 | * @return bool |
||
| 339 | */ |
||
| 340 | public function cropImage( |
||
| 362 | |||
| 363 | /** |
||
| 364 | * Watermark Image |
||
| 365 | * |
||
| 366 | * @param string $filename |
||
| 367 | * @param int $width |
||
| 368 | * @param int $height |
||
| 369 | * @param int $x |
||
| 370 | * @param int $y |
||
| 371 | * |
||
| 372 | * @return bool |
||
| 373 | */ |
||
| 374 | public function watermarkImage( |
||
| 403 | |||
| 404 | /** |
||
| 405 | * Dynamically handle calls into the query instance. |
||
| 406 | * |
||
| 407 | * @param string $method |
||
| 408 | * @param array $parameters |
||
| 409 | * @return mixed |
||
| 410 | */ |
||
| 411 | public function __call($method, $parameters) |
||
| 415 | } |
||
| 416 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.