Complex classes like FlysystemDriver 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 FlysystemDriver, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | abstract class FlysystemDriver extends AbstractHierarchicalFilesystemDriver |
||
20 | { |
||
21 | /** |
||
22 | * @var FilesystemInterface |
||
23 | */ |
||
24 | protected $filesystem; |
||
25 | |||
26 | /** |
||
27 | * @var AdapterInterface |
||
28 | */ |
||
29 | protected $adapter; |
||
30 | |||
31 | /** |
||
32 | * @var string |
||
33 | */ |
||
34 | protected $entryPath; |
||
35 | |||
36 | /** |
||
37 | * FlysystemDriver constructor. |
||
38 | * @param array $configuration |
||
39 | */ |
||
40 | 30 | public function __construct(array $configuration = []) |
|
49 | |||
50 | /** |
||
51 | * Processes the configuration for this driver. |
||
52 | * @return void |
||
53 | */ |
||
54 | public function processConfiguration() |
||
58 | |||
59 | /** |
||
60 | * Merges the capabilities merged by the user at the storage |
||
61 | * configuration into the actual capabilities of the driver |
||
62 | * and returns the result. |
||
63 | * |
||
64 | * @param int $capabilities |
||
65 | * @return int |
||
66 | */ |
||
67 | public function mergeConfigurationCapabilities($capabilities) |
||
71 | |||
72 | /** |
||
73 | * Returns the identifier of the root level folder of the storage. |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getRootLevelFolder() |
||
81 | |||
82 | /** |
||
83 | * Returns the identifier of the default folder new files should be put into. |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | 3 | public function getDefaultFolder() |
|
96 | |||
97 | /** |
||
98 | * Checks if a folder exists. |
||
99 | * |
||
100 | * @param string $folderIdentifier |
||
101 | * @return bool |
||
102 | */ |
||
103 | 6 | public function folderExists($folderIdentifier) |
|
111 | |||
112 | /** |
||
113 | * Creates a folder, within a parent folder. |
||
114 | * If no parent folder is given, a root level folder will be created |
||
115 | * |
||
116 | * @param string $newFolderName |
||
117 | * @param string $parentFolderIdentifier |
||
118 | * @param bool $recursive |
||
119 | * @return string the Identifier of the new folder |
||
120 | */ |
||
121 | 9 | public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false) |
|
137 | |||
138 | /** |
||
139 | * Returns the public URL to a file. |
||
140 | * Either fully qualified URL or relative to PATH_site (rawurlencoded). |
||
141 | * |
||
142 | * @param string $identifier |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getPublicUrl($identifier) |
||
152 | |||
153 | /** |
||
154 | * Renames a folder in this storage. |
||
155 | * |
||
156 | * @param string $folderIdentifier |
||
157 | * @param string $newName |
||
158 | * @return array A map of old to new file identifiers of all affected resources |
||
159 | */ |
||
160 | 3 | public function renameFolder($folderIdentifier, $newName) |
|
170 | |||
171 | /** |
||
172 | * Removes a folder in filesystem. |
||
173 | * |
||
174 | * @param string $folderIdentifier |
||
175 | * @param bool $deleteRecursively |
||
176 | * @return bool |
||
177 | */ |
||
178 | public function deleteFolder($folderIdentifier, $deleteRecursively = false) |
||
182 | |||
183 | /** |
||
184 | * Checks if a file exists. |
||
185 | * |
||
186 | * @param string $fileIdentifier |
||
187 | * @return bool |
||
188 | */ |
||
189 | 3 | public function fileExists($fileIdentifier) |
|
193 | |||
194 | /** |
||
195 | * Checks if a folder contains files and (if supported) other folders. |
||
196 | * |
||
197 | * @param string $folderIdentifier |
||
198 | * @return bool TRUE if there are no files and folders within $folder |
||
199 | */ |
||
200 | 3 | public function isFolderEmpty($folderIdentifier) |
|
204 | |||
205 | /** |
||
206 | * Adds a file from the local server hard disk to a given path in TYPO3s |
||
207 | * virtual file system. This assumes that the local file exists, so no |
||
208 | * further check is done here! After a successful the original file must |
||
209 | * not exist anymore. |
||
210 | * |
||
211 | * @param string $localFilePath (within PATH_site) |
||
212 | * @param string $targetFolderIdentifier |
||
213 | * @param string $newFileName optional, if not given original name is used |
||
214 | * @param bool $removeOriginal if set the original file will be removed |
||
215 | * after successful operation |
||
216 | * @return string the identifier of the new file |
||
217 | */ |
||
218 | 3 | public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true) |
|
244 | |||
245 | /** |
||
246 | * Creates a new (empty) file and returns the identifier. |
||
247 | * |
||
248 | * @param string $fileName |
||
249 | * @param string $parentFolderIdentifier |
||
250 | * @return string |
||
251 | */ |
||
252 | public function createFile($fileName, $parentFolderIdentifier) |
||
260 | |||
261 | /** |
||
262 | * Copies a file *within* the current storage. |
||
263 | * Note that this is only about an inner storage copy action, |
||
264 | * where a file is just copied to another folder in the same storage. |
||
265 | * |
||
266 | * @param string $fileIdentifier |
||
267 | * @param string $targetFolderIdentifier |
||
268 | * @param string $fileName |
||
269 | * @return string the Identifier of the new file |
||
270 | */ |
||
271 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
280 | |||
281 | /** |
||
282 | * Renames a file in this storage. |
||
283 | * |
||
284 | * @param string $fileIdentifier |
||
285 | * @param string $newName The target path (including the file name!) |
||
286 | * @return string The identifier of the file after renaming |
||
287 | */ |
||
288 | public function renameFile($fileIdentifier, $newName) |
||
296 | |||
297 | /** |
||
298 | * Replaces a file with file in local file system. |
||
299 | * |
||
300 | * @param string $fileIdentifier |
||
301 | * @param string $localFilePath |
||
302 | * @return bool TRUE if the operation succeeded |
||
303 | */ |
||
304 | public function replaceFile($fileIdentifier, $localFilePath) |
||
312 | |||
313 | /** |
||
314 | * Removes a file from the filesystem. This does not check if the file is |
||
315 | * still used or if it is a bad idea to delete it for some other reason |
||
316 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
317 | * |
||
318 | * @param string $fileIdentifier |
||
319 | * @return bool TRUE if deleting the file succeeded |
||
320 | */ |
||
321 | public function deleteFile($fileIdentifier) |
||
325 | |||
326 | /** |
||
327 | * Creates a hash for a file. |
||
328 | * |
||
329 | * @param string $fileIdentifier |
||
330 | * @param string $hashAlgorithm The hash algorithm to use |
||
331 | * @return string |
||
332 | */ |
||
333 | public function hash($fileIdentifier, $hashAlgorithm) |
||
337 | |||
338 | /** |
||
339 | * Moves a file *within* the current storage. |
||
340 | * Note that this is only about an inner-storage move action, |
||
341 | * where a file is just moved to another folder in the same storage. |
||
342 | * |
||
343 | * @param string $fileIdentifier |
||
344 | * @param string $targetFolderIdentifier |
||
345 | * @param string $newFileName |
||
346 | * @return string |
||
347 | */ |
||
348 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
||
352 | |||
353 | /** |
||
354 | * Folder equivalent to moveFileWithinStorage(). |
||
355 | * |
||
356 | * @param string $sourceFolderIdentifier |
||
357 | * @param string $targetFolderIdentifier |
||
358 | * @param string $newFolderName |
||
359 | * @return array All files which are affected, map of old => new file identifiers |
||
360 | */ |
||
361 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
365 | |||
366 | /** |
||
367 | * Folder equivalent to copyFileWithinStorage(). |
||
368 | * |
||
369 | * @param string $sourceFolderIdentifier |
||
370 | * @param string $targetFolderIdentifier |
||
371 | * @param string $newFolderName |
||
372 | * @return bool |
||
373 | */ |
||
374 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
378 | |||
379 | /** |
||
380 | * Returns the contents of a file. Beware that this requires to load the |
||
381 | * complete file into memory and also may require fetching the file from an |
||
382 | * external location. So this might be an expensive operation (both in terms |
||
383 | * of processing resources and money) for large files. |
||
384 | * |
||
385 | * @param string $fileIdentifier |
||
386 | * @return string The file contents |
||
387 | */ |
||
388 | 3 | public function getFileContents($fileIdentifier) |
|
392 | |||
393 | /** |
||
394 | * Sets the contents of a file to the specified value. |
||
395 | * |
||
396 | * @param string $fileIdentifier |
||
397 | * @param string $contents |
||
398 | * @return int The number of bytes written to the file |
||
399 | */ |
||
400 | 3 | public function setFileContents($fileIdentifier, $contents) |
|
406 | |||
407 | /** |
||
408 | * Checks if a file inside a folder exists |
||
409 | * |
||
410 | * @param string $fileName |
||
411 | * @param string $folderIdentifier |
||
412 | * @return bool |
||
413 | */ |
||
414 | public function fileExistsInFolder($fileName, $folderIdentifier) |
||
418 | |||
419 | /** |
||
420 | * Checks if a folder inside a folder exists. |
||
421 | * |
||
422 | * @param string $folderName |
||
423 | * @param string $folderIdentifier |
||
424 | * @return bool |
||
425 | */ |
||
426 | public function folderExistsInFolder($folderName, $folderIdentifier) |
||
430 | |||
431 | /** |
||
432 | * Returns a path to a local copy of a file for processing it. When changing the |
||
433 | * file, you have to take care of replacing the current version yourself! |
||
434 | * |
||
435 | * @param string $fileIdentifier |
||
436 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
437 | * operations. This might speed up things, e.g. by using |
||
438 | * a cached local version. Never modify the file if you |
||
439 | * have set this flag! |
||
440 | * @return string The path to the file on the local disk |
||
441 | */ |
||
442 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
450 | |||
451 | /** |
||
452 | * Returns the permissions of a file/folder as an array |
||
453 | * (keys r, w) of boolean flags |
||
454 | * |
||
455 | * @param string $identifier |
||
456 | * @return array |
||
457 | */ |
||
458 | public function getPermissions($identifier) |
||
465 | |||
466 | /** |
||
467 | * Directly output the contents of the file to the output |
||
468 | * buffer. Should not take care of header files or flushing |
||
469 | * buffer before. Will be taken care of by the Storage. |
||
470 | * |
||
471 | * @param string $identifier |
||
472 | * @return void |
||
473 | */ |
||
474 | public function dumpFileContents($identifier) |
||
481 | |||
482 | /** |
||
483 | * Checks if a given identifier is within a container, e.g. if |
||
484 | * a file or folder is within another folder. |
||
485 | * This can e.g. be used to check for web-mounts. |
||
486 | * |
||
487 | * Hint: this also needs to return TRUE if the given identifier |
||
488 | * matches the container identifier to allow access to the root |
||
489 | * folder of a filemount. |
||
490 | * |
||
491 | * @param string $folderIdentifier |
||
492 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
493 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
494 | */ |
||
495 | public function isWithin($folderIdentifier, $identifier) |
||
514 | |||
515 | /** |
||
516 | * Returns information about a file. |
||
517 | * |
||
518 | * @param string $fileIdentifier |
||
519 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
520 | * If empty all will be extracted |
||
521 | * @return array |
||
522 | */ |
||
523 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = array()) |
||
531 | |||
532 | /** |
||
533 | * Returns information about a file. |
||
534 | * |
||
535 | * @param string $folderIdentifier |
||
536 | * @return array |
||
537 | */ |
||
538 | public function getFolderInfoByIdentifier($folderIdentifier) |
||
551 | |||
552 | /** |
||
553 | * Returns the identifier of a file inside the folder |
||
554 | * |
||
555 | * @param string $fileName |
||
556 | * @param string $folderIdentifier |
||
557 | * @return string file identifier |
||
558 | */ |
||
559 | public function getFileInFolder($fileName, $folderIdentifier) |
||
567 | |||
568 | /** |
||
569 | * Returns a list of files inside the specified path |
||
570 | * |
||
571 | * @param string $folderIdentifier |
||
572 | * @param int $start |
||
573 | * @param int $numberOfItems |
||
574 | * @param bool $recursive |
||
575 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
576 | * @param string $sort Property name used to sort the items. |
||
577 | * Among them may be: '' (empty, no sorting), name, |
||
578 | * fileext, size, tstamp and rw. |
||
579 | * If a driver does not support the given property, it |
||
580 | * should fall back to "name". |
||
581 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
582 | * @return array of FileIdentifiers |
||
583 | */ |
||
584 | 3 | public function getFilesInFolder( |
|
609 | |||
610 | /** |
||
611 | * Returns the identifier of a folder inside the folder |
||
612 | * |
||
613 | * @param string $folderName The name of the target folder |
||
614 | * @param string $folderIdentifier |
||
615 | * @return string folder identifier |
||
616 | */ |
||
617 | public function getFolderInFolder($folderName, $folderIdentifier) |
||
625 | |||
626 | /** |
||
627 | * Returns a list of folders inside the specified path |
||
628 | * |
||
629 | * @param string $folderIdentifier |
||
630 | * @param int $start |
||
631 | * @param int $numberOfItems |
||
632 | * @param bool $recursive |
||
633 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
634 | * @param string $sort Property name used to sort the items. |
||
635 | * Among them may be: '' (empty, no sorting), name, |
||
636 | * fileext, size, tstamp and rw. |
||
637 | * If a driver does not support the given property, it |
||
638 | * should fall back to "name". |
||
639 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
640 | * @return array of Folder Identifier |
||
641 | * @TODO: Implement pagination with $start and $numberOfItems |
||
642 | * @TODO: Implement directory filter callbacks |
||
643 | * @TODO: Implement sorting |
||
644 | */ |
||
645 | 3 | public function getFoldersInFolder( |
|
670 | |||
671 | /** |
||
672 | * Returns the number of files inside the specified path |
||
673 | * |
||
674 | * @param string $folderIdentifier |
||
675 | * @param bool $recursive |
||
676 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
677 | * @return int Number of files in folder |
||
678 | * @TODO: Implement recursive count |
||
679 | * @TODO: Implement filename filtering |
||
680 | */ |
||
681 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = array()) |
||
686 | |||
687 | /** |
||
688 | * Returns the number of folders inside the specified path |
||
689 | * |
||
690 | * @param string $folderIdentifier |
||
691 | * @param bool $recursive |
||
692 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
693 | * @return int Number of folders in folder |
||
694 | */ |
||
695 | public function countFoldersInFolder( |
||
707 | } |
||
708 |