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 | 27 | 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 | 12 | public function exists($filename) |
|
53 | |||
54 | /** |
||
55 | * Get Size |
||
56 | * |
||
57 | * @param string $filename Path File |
||
58 | * |
||
59 | * @return bool |
||
60 | */ |
||
61 | 2 | public function size($filename) |
|
70 | |||
71 | /** |
||
72 | * Get MimeType File |
||
73 | * |
||
74 | * @param string $filename Path File |
||
75 | * |
||
76 | * @return bool |
||
77 | */ |
||
78 | 12 | public function mimeType($filename) |
|
87 | |||
88 | /** |
||
89 | * Path is Directory |
||
90 | * |
||
91 | * @param string $path Path Directory |
||
92 | * |
||
93 | * @return bool |
||
94 | */ |
||
95 | 10 | public function isDir($path) |
|
105 | |||
106 | /** |
||
107 | * Is File |
||
108 | * |
||
109 | * @param string $filename Path File |
||
110 | * |
||
111 | * @return bool |
||
112 | */ |
||
113 | 6 | public function isFile($filename) |
|
117 | |||
118 | /** |
||
119 | * Get Meta Data |
||
120 | * |
||
121 | * @param string $filename Path File |
||
122 | * |
||
123 | * @return bool |
||
124 | */ |
||
125 | 2 | public function metaData($filename) |
|
134 | |||
135 | /** |
||
136 | * Read Content File |
||
137 | * |
||
138 | * @param string $filename Path File |
||
139 | * |
||
140 | * @return bool |
||
141 | */ |
||
142 | 1 | public function readFile($filename) |
|
146 | |||
147 | /** |
||
148 | * Delete File |
||
149 | * |
||
150 | * @param string $filename Path File |
||
151 | * |
||
152 | * @return bool |
||
153 | */ |
||
154 | 2 | public function deleteFile($filename) |
|
162 | |||
163 | /** |
||
164 | * Delete Folder |
||
165 | * |
||
166 | * @param string $folder |
||
167 | * |
||
168 | * @return bool |
||
169 | */ |
||
170 | 2 | public function deleteFolder($folder) |
|
178 | |||
179 | /** |
||
180 | * Move a file to a new location. |
||
181 | * |
||
182 | * @param string $from |
||
183 | * @param string $to |
||
184 | * @return bool |
||
185 | */ |
||
186 | 1 | public function move($from, $to) |
|
190 | |||
191 | /** |
||
192 | * Copy a file to a new location. |
||
193 | * |
||
194 | * @param string $from |
||
195 | * @param string $to |
||
196 | * @return bool |
||
197 | */ |
||
198 | 1 | public function copy($from, $to) |
|
202 | |||
203 | /** |
||
204 | * Files in Folder |
||
205 | * |
||
206 | * @param string $path |
||
207 | * @param bool $recursive |
||
208 | * |
||
209 | * @return array |
||
210 | */ |
||
211 | 2 | public function files($path, $recursive = false) |
|
219 | |||
220 | /** |
||
221 | * UploadFile |
||
222 | * |
||
223 | * @param UploadedFile $file Uploaded File |
||
224 | * @param string $folder String Folder |
||
225 | * @param string $name String Name |
||
226 | * @param bool $override Boolean Over Ride |
||
227 | * |
||
228 | * @return bool |
||
229 | */ |
||
230 | 2 | public function uploadFile(UploadedFile $file, $folder = null, $name = null, $override = false) |
|
242 | |||
243 | /** |
||
244 | * Upload Image |
||
245 | * |
||
246 | * @param UploadedFile $file Uploaded File |
||
247 | * @param string $folder String Folder |
||
248 | * @param string $name String Name |
||
249 | * @param array $options Array Options |
||
250 | * @param bool $override Boolean Over Ride |
||
251 | * |
||
252 | * @return bool |
||
253 | */ |
||
254 | 4 | public function uploadImage( |
|
292 | |||
293 | /** |
||
294 | * Parse Filename |
||
295 | * |
||
296 | * @param UploadedFile $file Uploaded File |
||
297 | * @param string $name String Name |
||
298 | * @param string $folder String Folder |
||
299 | * @param bool $override Boolean Over Ride |
||
300 | * |
||
301 | * @return bool|array |
||
302 | */ |
||
303 | 6 | protected function parseFile($file, $folder = null, $name = null, $override = false) |
|
331 | } |
||
332 |
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.