Total Complexity | 63 |
Total Lines | 447 |
Duplicated Lines | 0 % |
Changes | 0 |
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.
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) { |
||
48 | $this->rootFolderClosure = $rootFolderClosure; |
||
49 | } |
||
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) { |
||
60 | if ($this->rootFolder === null) { |
||
61 | $this->rootFolder = call_user_func($this->rootFolderClosure); |
||
62 | } |
||
63 | |||
64 | return call_user_func_array([$this->rootFolder, $method], $args); |
||
65 | } |
||
66 | |||
67 | /** |
||
68 | * @inheritDoc |
||
69 | */ |
||
70 | public function getUser() { |
||
71 | return $this->__call(__FUNCTION__, func_get_args()); |
||
72 | } |
||
73 | |||
74 | /** |
||
75 | * @inheritDoc |
||
76 | */ |
||
77 | public function listen($scope, $method, callable $callback) { |
||
78 | $this->__call(__FUNCTION__, func_get_args()); |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @inheritDoc |
||
83 | */ |
||
84 | public function removeListener($scope = null, $method = null, callable $callback = null) { |
||
85 | $this->__call(__FUNCTION__, func_get_args()); |
||
86 | } |
||
87 | |||
88 | /** |
||
89 | * @inheritDoc |
||
90 | */ |
||
91 | public function emit($scope, $method, $arguments = array()) { |
||
92 | $this->__call(__FUNCTION__, func_get_args()); |
||
93 | } |
||
94 | |||
95 | /** |
||
96 | * @inheritDoc |
||
97 | */ |
||
98 | public function mount($storage, $mountPoint, $arguments = array()) { |
||
99 | $this->__call(__FUNCTION__, func_get_args()); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * @inheritDoc |
||
104 | */ |
||
105 | public function getMount($mountPoint) { |
||
106 | return $this->__call(__FUNCTION__, func_get_args()); |
||
107 | } |
||
108 | |||
109 | /** |
||
110 | * @inheritDoc |
||
111 | */ |
||
112 | public function getMountsIn($mountPoint) { |
||
113 | return $this->__call(__FUNCTION__, func_get_args()); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * @inheritDoc |
||
118 | */ |
||
119 | public function getMountByStorageId($storageId) { |
||
120 | return $this->__call(__FUNCTION__, func_get_args()); |
||
121 | } |
||
122 | |||
123 | /** |
||
124 | * @inheritDoc |
||
125 | */ |
||
126 | public function getMountByNumericStorageId($numericId) { |
||
127 | return $this->__call(__FUNCTION__, func_get_args()); |
||
128 | } |
||
129 | |||
130 | /** |
||
131 | * @inheritDoc |
||
132 | */ |
||
133 | public function unMount($mount) { |
||
134 | $this->__call(__FUNCTION__, func_get_args()); |
||
135 | } |
||
136 | |||
137 | /** |
||
138 | * @inheritDoc |
||
139 | */ |
||
140 | public function get($path) { |
||
141 | return $this->__call(__FUNCTION__, func_get_args()); |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @inheritDoc |
||
146 | */ |
||
147 | public function rename($targetPath) { |
||
149 | } |
||
150 | |||
151 | /** |
||
152 | * @inheritDoc |
||
153 | */ |
||
154 | public function delete() { |
||
155 | return $this->__call(__FUNCTION__, func_get_args()); |
||
156 | } |
||
157 | |||
158 | /** |
||
159 | * @inheritDoc |
||
160 | */ |
||
161 | public function copy($targetPath) { |
||
162 | return $this->__call(__FUNCTION__, func_get_args()); |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @inheritDoc |
||
167 | */ |
||
168 | public function touch($mtime = null) { |
||
169 | $this->__call(__FUNCTION__, func_get_args()); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * @inheritDoc |
||
174 | */ |
||
175 | public function getStorage() { |
||
176 | return $this->__call(__FUNCTION__, func_get_args()); |
||
177 | } |
||
178 | |||
179 | /** |
||
180 | * @inheritDoc |
||
181 | */ |
||
182 | public function getPath() { |
||
183 | return $this->__call(__FUNCTION__, func_get_args()); |
||
184 | } |
||
185 | |||
186 | /** |
||
187 | * @inheritDoc |
||
188 | */ |
||
189 | public function getInternalPath() { |
||
190 | return $this->__call(__FUNCTION__, func_get_args()); |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @inheritDoc |
||
195 | */ |
||
196 | public function getId() { |
||
197 | return $this->__call(__FUNCTION__, func_get_args()); |
||
198 | } |
||
199 | |||
200 | /** |
||
201 | * @inheritDoc |
||
202 | */ |
||
203 | public function stat() { |
||
204 | return $this->__call(__FUNCTION__, func_get_args()); |
||
205 | } |
||
206 | |||
207 | /** |
||
208 | * @inheritDoc |
||
209 | */ |
||
210 | public function getMTime() { |
||
211 | return $this->__call(__FUNCTION__, func_get_args()); |
||
212 | } |
||
213 | |||
214 | /** |
||
215 | * @inheritDoc |
||
216 | */ |
||
217 | public function getSize() { |
||
218 | return $this->__call(__FUNCTION__, func_get_args()); |
||
219 | } |
||
220 | |||
221 | /** |
||
222 | * @inheritDoc |
||
223 | */ |
||
224 | public function getEtag() { |
||
225 | return $this->__call(__FUNCTION__, func_get_args()); |
||
226 | } |
||
227 | |||
228 | /** |
||
229 | * @inheritDoc |
||
230 | */ |
||
231 | public function getPermissions() { |
||
232 | return $this->__call(__FUNCTION__, func_get_args()); |
||
233 | } |
||
234 | |||
235 | /** |
||
236 | * @inheritDoc |
||
237 | */ |
||
238 | public function isReadable() { |
||
239 | return $this->__call(__FUNCTION__, func_get_args()); |
||
240 | } |
||
241 | |||
242 | /** |
||
243 | * @inheritDoc |
||
244 | */ |
||
245 | public function isUpdateable() { |
||
246 | return $this->__call(__FUNCTION__, func_get_args()); |
||
247 | } |
||
248 | |||
249 | /** |
||
250 | * @inheritDoc |
||
251 | */ |
||
252 | public function isDeletable() { |
||
254 | } |
||
255 | |||
256 | /** |
||
257 | * @inheritDoc |
||
258 | */ |
||
259 | public function isShareable() { |
||
260 | return $this->__call(__FUNCTION__, func_get_args()); |
||
261 | } |
||
262 | |||
263 | /** |
||
264 | * @inheritDoc |
||
265 | */ |
||
266 | public function getParent() { |
||
267 | return $this->__call(__FUNCTION__, func_get_args()); |
||
268 | } |
||
269 | |||
270 | /** |
||
271 | * @inheritDoc |
||
272 | */ |
||
273 | public function getName() { |
||
274 | return $this->__call(__FUNCTION__, func_get_args()); |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * @inheritDoc |
||
279 | */ |
||
280 | public function getUserFolder($userId) { |
||
281 | return $this->__call(__FUNCTION__, func_get_args()); |
||
282 | } |
||
283 | |||
284 | /** |
||
285 | * @inheritDoc |
||
286 | */ |
||
287 | public function getMimetype() { |
||
288 | return $this->__call(__FUNCTION__, func_get_args()); |
||
289 | } |
||
290 | |||
291 | /** |
||
292 | * @inheritDoc |
||
293 | */ |
||
294 | public function getMimePart() { |
||
295 | return $this->__call(__FUNCTION__, func_get_args()); |
||
296 | } |
||
297 | |||
298 | /** |
||
299 | * @inheritDoc |
||
300 | */ |
||
301 | public function isEncrypted() { |
||
303 | } |
||
304 | |||
305 | /** |
||
306 | * @inheritDoc |
||
307 | */ |
||
308 | public function getType() { |
||
309 | return $this->__call(__FUNCTION__, func_get_args()); |
||
310 | } |
||
311 | |||
312 | /** |
||
313 | * @inheritDoc |
||
314 | */ |
||
315 | public function isShared() { |
||
316 | return $this->__call(__FUNCTION__, func_get_args()); |
||
317 | } |
||
318 | |||
319 | /** |
||
320 | * @inheritDoc |
||
321 | */ |
||
322 | public function isMounted() { |
||
324 | } |
||
325 | |||
326 | /** |
||
327 | * @inheritDoc |
||
328 | */ |
||
329 | public function getMountPoint() { |
||
330 | return $this->__call(__FUNCTION__, func_get_args()); |
||
331 | } |
||
332 | |||
333 | /** |
||
334 | * @inheritDoc |
||
335 | */ |
||
336 | public function getOwner() { |
||
337 | return $this->__call(__FUNCTION__, func_get_args()); |
||
338 | } |
||
339 | |||
340 | /** |
||
341 | * @inheritDoc |
||
342 | */ |
||
343 | public function getChecksum() { |
||
345 | } |
||
346 | |||
347 | public function getExtension(): string { |
||
348 | return $this->__call(__FUNCTION__, func_get_args()); |
||
349 | } |
||
350 | |||
351 | /** |
||
352 | * @inheritDoc |
||
353 | */ |
||
354 | public function getFullPath($path) { |
||
355 | return $this->__call(__FUNCTION__, func_get_args()); |
||
356 | } |
||
357 | |||
358 | /** |
||
359 | * @inheritDoc |
||
360 | */ |
||
361 | public function getRelativePath($path) { |
||
362 | return $this->__call(__FUNCTION__, func_get_args()); |
||
363 | } |
||
364 | |||
365 | /** |
||
366 | * @inheritDoc |
||
367 | */ |
||
368 | public function isSubNode($node) { |
||
369 | return $this->__call(__FUNCTION__, func_get_args()); |
||
370 | } |
||
371 | |||
372 | /** |
||
373 | * @inheritDoc |
||
374 | */ |
||
375 | public function getDirectoryListing() { |
||
376 | return $this->__call(__FUNCTION__, func_get_args()); |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * @inheritDoc |
||
381 | */ |
||
382 | public function nodeExists($path) { |
||
383 | return $this->__call(__FUNCTION__, func_get_args()); |
||
384 | } |
||
385 | |||
386 | /** |
||
387 | * @inheritDoc |
||
388 | */ |
||
389 | public function newFolder($path) { |
||
390 | return $this->__call(__FUNCTION__, func_get_args()); |
||
391 | } |
||
392 | |||
393 | /** |
||
394 | * @inheritDoc |
||
395 | */ |
||
396 | public function newFile($path) { |
||
397 | return $this->__call(__FUNCTION__, func_get_args()); |
||
398 | } |
||
399 | |||
400 | /** |
||
401 | * @inheritDoc |
||
402 | */ |
||
403 | public function search($query) { |
||
404 | return $this->__call(__FUNCTION__, func_get_args()); |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * @inheritDoc |
||
409 | */ |
||
410 | public function searchByMime($mimetype) { |
||
411 | return $this->__call(__FUNCTION__, func_get_args()); |
||
412 | } |
||
413 | |||
414 | /** |
||
415 | * @inheritDoc |
||
416 | */ |
||
417 | public function searchByTag($tag, $userId) { |
||
418 | return $this->__call(__FUNCTION__, func_get_args()); |
||
419 | } |
||
420 | |||
421 | /** |
||
422 | * @inheritDoc |
||
423 | */ |
||
424 | public function getById($id) { |
||
425 | return $this->__call(__FUNCTION__, func_get_args()); |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * @inheritDoc |
||
430 | */ |
||
431 | public function getFreeSpace() { |
||
432 | return $this->__call(__FUNCTION__, func_get_args()); |
||
433 | } |
||
434 | |||
435 | /** |
||
436 | * @inheritDoc |
||
437 | */ |
||
438 | public function isCreatable() { |
||
439 | return $this->__call(__FUNCTION__, func_get_args()); |
||
440 | } |
||
441 | |||
442 | /** |
||
443 | * @inheritDoc |
||
444 | */ |
||
445 | public function getNonExistingName($name) { |
||
446 | return $this->__call(__FUNCTION__, func_get_args()); |
||
447 | } |
||
448 | |||
449 | /** |
||
450 | * @inheritDoc |
||
451 | */ |
||
452 | public function move($targetPath) { |
||
453 | return $this->__call(__FUNCTION__, func_get_args()); |
||
454 | } |
||
455 | |||
456 | /** |
||
457 | * @inheritDoc |
||
458 | */ |
||
459 | public function lock($type) { |
||
460 | return $this->__call(__FUNCTION__, func_get_args()); |
||
461 | } |
||
462 | |||
463 | /** |
||
464 | * @inheritDoc |
||
465 | */ |
||
466 | public function changeLock($targetType) { |
||
467 | return $this->__call(__FUNCTION__, func_get_args()); |
||
468 | } |
||
469 | |||
470 | /** |
||
471 | * @inheritDoc |
||
472 | */ |
||
473 | public function unlock($type) { |
||
474 | return $this->__call(__FUNCTION__, func_get_args()); |
||
475 | } |
||
476 | |||
477 | /** |
||
478 | * @inheritDoc |
||
479 | */ |
||
480 | public function getRecent($limit, $offset = 0) { |
||
482 | } |
||
483 | } |
||
484 |