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 |
||
13 | class StorageManager |
||
14 | { |
||
15 | /** |
||
16 | * @var Storage |
||
17 | */ |
||
18 | protected $storage; |
||
19 | |||
20 | /** |
||
21 | * @var ImagineFactory |
||
22 | */ |
||
23 | protected $imagineFactory; |
||
24 | |||
25 | /** |
||
26 | * Construct |
||
27 | * |
||
28 | * @param Storage $storage |
||
29 | * @param ImagineFactory $imagineFactory |
||
30 | */ |
||
31 | public function __construct(Storage $storage, ImagineFactory $imagineFactory = null) |
||
36 | |||
37 | /** |
||
38 | * File Exists |
||
39 | * |
||
40 | * @param string $filename Path File |
||
41 | * |
||
42 | * @return bool |
||
43 | */ |
||
44 | public function exists($filename) |
||
53 | |||
54 | /** |
||
55 | * Get Size |
||
56 | * |
||
57 | * @param string $filename Path File |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | public function size($filename) |
||
70 | |||
71 | /** |
||
72 | * Get MimeType File |
||
73 | * |
||
74 | * @param string $filename Path File |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | public function mimeType($filename) |
||
87 | |||
88 | /** |
||
89 | * Path is Directory |
||
90 | * |
||
91 | * @param string $path Path Directory |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | public function isDir($path) |
||
105 | |||
106 | /** |
||
107 | * Is File |
||
108 | * |
||
109 | * @param string $filename Path File |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | public function isFile($filename) |
||
117 | |||
118 | /** |
||
119 | * Get Meta Data |
||
120 | * |
||
121 | * @param string $filename Path File |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | public function metaData($filename) |
||
134 | |||
135 | /** |
||
136 | * Read Content File |
||
137 | * |
||
138 | * @param string $filename Path File |
||
139 | * |
||
140 | * @return string |
||
141 | */ |
||
142 | public function readFile($filename) |
||
146 | |||
147 | /** |
||
148 | * Delete File |
||
149 | * |
||
150 | * @param string $filename Path File |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | public function deleteFile($filename) |
||
162 | |||
163 | /** |
||
164 | * Delete Folder |
||
165 | * |
||
166 | * @param string $folder |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | public function deleteFolder($folder) |
||
178 | |||
179 | /** |
||
180 | * Files in Folder |
||
181 | * |
||
182 | * @param string $path |
||
183 | * @param bool $recursive |
||
184 | * |
||
185 | * @return array |
||
186 | */ |
||
187 | public function files($path, $recursive = false) |
||
195 | |||
196 | /** |
||
197 | * UploadFile |
||
198 | * |
||
199 | * @param UploadedFile $file Uploaded File |
||
200 | * @param string $folder String Folder |
||
201 | * @param string $name String Name |
||
202 | * @param bool $override Boolean Over Ride |
||
203 | * @param array $config Array Config Upload |
||
204 | * |
||
205 | * @return bool |
||
206 | */ |
||
207 | public function uploadFile(UploadedFile $file, $folder = null, $name = null, $override = false, array $config = []) |
||
219 | |||
220 | /** |
||
221 | * Upload Image |
||
222 | * |
||
223 | * @param UploadedFile $file Uploaded File |
||
224 | * @param string $folder String Folder |
||
225 | * @param string $name String Name |
||
226 | * @param array $options Array Options |
||
227 | * @param bool $override Boolean Over Ride |
||
228 | * @param array $config Array Config Upload |
||
229 | * |
||
230 | * @return bool |
||
231 | */ |
||
232 | public function uploadImage( |
||
271 | |||
272 | /** |
||
273 | * Parse Filename |
||
274 | * |
||
275 | * @param UploadedFile $file Uploaded File |
||
276 | * @param string $name String Name |
||
277 | * @param string $folder String Folder |
||
278 | * @param bool $override Boolean Over Ride |
||
279 | * |
||
280 | * @return bool|array |
||
281 | */ |
||
282 | protected function parseFile($file, $folder = null, $name = null, $override = false) |
||
310 | |||
311 | /** |
||
312 | * Crop Image |
||
313 | * |
||
314 | * @param string $filename |
||
315 | * @param int $width |
||
316 | * @param int $height |
||
317 | * @param int $x |
||
318 | * @param int $y |
||
319 | * |
||
320 | * @return bool |
||
321 | */ |
||
322 | public function cropImage( |
||
323 | $filename, |
||
324 | $width, |
||
325 | $height, |
||
326 | $x, |
||
327 | $y, |
||
328 | $target = null |
||
329 | ) { |
||
330 | if (!$this->imagineFactory) { |
||
331 | return false; |
||
332 | } |
||
333 | |||
334 | $image = $this->storage->get($filename); |
||
335 | $imagine = $this->imagineFactory->make($image); |
||
336 | $imagine->crop($width, $height, $x, $y); |
||
337 | $content = $imagine->encode(); |
||
338 | |||
339 | if (!$target) { |
||
340 | $target = $filename; |
||
341 | } |
||
342 | |||
343 | return $this->storage->put($target, $content); |
||
344 | } |
||
345 | |||
346 | /** |
||
347 | * Dynamically handle calls into the query instance. |
||
348 | * |
||
349 | * @param string $method |
||
350 | * @param array $parameters |
||
351 | * @return mixed |
||
352 | */ |
||
353 | public function __call($method, $parameters) |
||
357 | } |
||
358 |
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.