Complex classes like LazyRoot 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 LazyRoot, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
35 | class LazyRoot implements IRootFolder { |
||
36 | /** @var \Closure */ |
||
37 | private $rootFolderClosure; |
||
38 | |||
39 | /** @var IRootFolder */ |
||
40 | private $rootFolder; |
||
41 | |||
42 | /** |
||
43 | * LazyRoot constructor. |
||
44 | * |
||
45 | * @param \Closure $rootFolderClosure |
||
46 | */ |
||
47 | public function __construct(\Closure $rootFolderClosure) { |
||
50 | |||
51 | /** |
||
52 | * Magic method to first get the real rootFolder and then |
||
53 | * call $method with $args on it |
||
54 | * |
||
55 | * @param $method |
||
56 | * @param $args |
||
57 | * @return mixed |
||
58 | */ |
||
59 | public function __call($method, $args) { |
||
66 | |||
67 | /** |
||
68 | * @inheritDoc |
||
69 | */ |
||
70 | public function getUser() { |
||
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | */ |
||
77 | public function listen($scope, $method, callable $callback) { |
||
80 | |||
81 | /** |
||
82 | * @inheritDoc |
||
83 | */ |
||
84 | public function removeListener($scope = null, $method = null, callable $callback = null) { |
||
87 | |||
88 | /** |
||
89 | * @inheritDoc |
||
90 | */ |
||
91 | public function emit($scope, $method, $arguments = array()) { |
||
94 | |||
95 | /** |
||
96 | * @inheritDoc |
||
97 | */ |
||
98 | public function mount($storage, $mountPoint, $arguments = array()) { |
||
101 | |||
102 | /** |
||
103 | * @inheritDoc |
||
104 | */ |
||
105 | public function getMount($mountPoint) { |
||
108 | |||
109 | /** |
||
110 | * @inheritDoc |
||
111 | */ |
||
112 | public function getMountsIn($mountPoint) { |
||
115 | |||
116 | /** |
||
117 | * @inheritDoc |
||
118 | */ |
||
119 | public function getMountByStorageId($storageId) { |
||
122 | |||
123 | /** |
||
124 | * @inheritDoc |
||
125 | */ |
||
126 | public function getMountByNumericStorageId($numericId) { |
||
129 | |||
130 | /** |
||
131 | * @inheritDoc |
||
132 | */ |
||
133 | public function unMount($mount) { |
||
136 | |||
137 | /** |
||
138 | * @inheritDoc |
||
139 | */ |
||
140 | public function get($path) { |
||
143 | |||
144 | /** |
||
145 | * @inheritDoc |
||
146 | */ |
||
147 | public function rename($targetPath) { |
||
150 | |||
151 | /** |
||
152 | * @inheritDoc |
||
153 | */ |
||
154 | public function delete() { |
||
157 | |||
158 | /** |
||
159 | * @inheritDoc |
||
160 | */ |
||
161 | public function copy($targetPath) { |
||
164 | |||
165 | /** |
||
166 | * @inheritDoc |
||
167 | */ |
||
168 | public function touch($mtime = null) { |
||
171 | |||
172 | /** |
||
173 | * @inheritDoc |
||
174 | */ |
||
175 | public function getStorage() { |
||
178 | |||
179 | /** |
||
180 | * @inheritDoc |
||
181 | */ |
||
182 | public function getPath() { |
||
185 | |||
186 | /** |
||
187 | * @inheritDoc |
||
188 | */ |
||
189 | public function getInternalPath() { |
||
192 | |||
193 | /** |
||
194 | * @inheritDoc |
||
195 | */ |
||
196 | public function getId() { |
||
199 | |||
200 | /** |
||
201 | * @inheritDoc |
||
202 | */ |
||
203 | public function stat() { |
||
206 | |||
207 | /** |
||
208 | * @inheritDoc |
||
209 | */ |
||
210 | public function getMTime() { |
||
213 | |||
214 | /** |
||
215 | * @inheritDoc |
||
216 | */ |
||
217 | public function getSize() { |
||
220 | |||
221 | /** |
||
222 | * @inheritDoc |
||
223 | */ |
||
224 | public function getEtag() { |
||
227 | |||
228 | /** |
||
229 | * @inheritDoc |
||
230 | */ |
||
231 | public function getPermissions() { |
||
234 | |||
235 | /** |
||
236 | * @inheritDoc |
||
237 | */ |
||
238 | public function isReadable() { |
||
241 | |||
242 | /** |
||
243 | * @inheritDoc |
||
244 | */ |
||
245 | public function isUpdateable() { |
||
248 | |||
249 | /** |
||
250 | * @inheritDoc |
||
251 | */ |
||
252 | public function isDeletable() { |
||
255 | |||
256 | /** |
||
257 | * @inheritDoc |
||
258 | */ |
||
259 | public function isShareable() { |
||
262 | |||
263 | /** |
||
264 | * @inheritDoc |
||
265 | */ |
||
266 | public function getParent() { |
||
269 | |||
270 | /** |
||
271 | * @inheritDoc |
||
272 | */ |
||
273 | public function getName() { |
||
276 | |||
277 | /** |
||
278 | * @inheritDoc |
||
279 | */ |
||
280 | public function getUserFolder($userId) { |
||
283 | |||
284 | /** |
||
285 | * @inheritDoc |
||
286 | */ |
||
287 | public function getMimetype() { |
||
290 | |||
291 | /** |
||
292 | * @inheritDoc |
||
293 | */ |
||
294 | public function getMimePart() { |
||
297 | |||
298 | /** |
||
299 | * @inheritDoc |
||
300 | */ |
||
301 | public function isEncrypted() { |
||
304 | |||
305 | /** |
||
306 | * @inheritDoc |
||
307 | */ |
||
308 | public function getType() { |
||
311 | |||
312 | /** |
||
313 | * @inheritDoc |
||
314 | */ |
||
315 | public function isShared() { |
||
318 | |||
319 | /** |
||
320 | * @inheritDoc |
||
321 | */ |
||
322 | public function isMounted() { |
||
325 | |||
326 | /** |
||
327 | * @inheritDoc |
||
328 | */ |
||
329 | public function getMountPoint() { |
||
332 | |||
333 | /** |
||
334 | * @inheritDoc |
||
335 | */ |
||
336 | public function getOwner() { |
||
339 | |||
340 | /** |
||
341 | * @inheritDoc |
||
342 | */ |
||
343 | public function getChecksum() { |
||
346 | |||
347 | /** |
||
348 | * @inheritDoc |
||
349 | */ |
||
350 | public function getFullPath($path) { |
||
353 | |||
354 | /** |
||
355 | * @inheritDoc |
||
356 | */ |
||
357 | public function getRelativePath($path) { |
||
360 | |||
361 | /** |
||
362 | * @inheritDoc |
||
363 | */ |
||
364 | public function isSubNode($node) { |
||
367 | |||
368 | /** |
||
369 | * @inheritDoc |
||
370 | */ |
||
371 | public function getDirectoryListing() { |
||
374 | |||
375 | /** |
||
376 | * @inheritDoc |
||
377 | */ |
||
378 | public function nodeExists($path) { |
||
381 | |||
382 | /** |
||
383 | * @inheritDoc |
||
384 | */ |
||
385 | public function newFolder($path) { |
||
388 | |||
389 | /** |
||
390 | * @inheritDoc |
||
391 | */ |
||
392 | public function newFile($path) { |
||
395 | |||
396 | /** |
||
397 | * @inheritDoc |
||
398 | */ |
||
399 | public function search($query) { |
||
402 | |||
403 | /** |
||
404 | * @inheritDoc |
||
405 | */ |
||
406 | public function searchByMime($mimetype) { |
||
409 | |||
410 | /** |
||
411 | * @inheritDoc |
||
412 | */ |
||
413 | public function searchByTag($tag, $userId) { |
||
416 | |||
417 | /** |
||
418 | * @inheritDoc |
||
419 | */ |
||
420 | public function getById($id) { |
||
423 | |||
424 | /** |
||
425 | * @inheritDoc |
||
426 | */ |
||
427 | public function getFreeSpace() { |
||
430 | |||
431 | /** |
||
432 | * @inheritDoc |
||
433 | */ |
||
434 | public function isCreatable() { |
||
437 | |||
438 | /** |
||
439 | * @inheritDoc |
||
440 | */ |
||
441 | public function getNonExistingName($name) { |
||
444 | |||
445 | /** |
||
446 | * @inheritDoc |
||
447 | */ |
||
448 | public function move($targetPath) { |
||
451 | |||
452 | /** |
||
453 | * @inheritDoc |
||
454 | */ |
||
455 | public function lock($type) { |
||
458 | |||
459 | /** |
||
460 | * @inheritDoc |
||
461 | */ |
||
462 | public function changeLock($targetType) { |
||
465 | |||
466 | /** |
||
467 | * @inheritDoc |
||
468 | */ |
||
469 | public function unlock($type) { |
||
472 | |||
473 | |||
474 | } |
||
475 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.