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 |
||
48 | abstract class FlysystemDriver extends AbstractHierarchicalFilesystemDriver |
||
49 | { |
||
50 | /** |
||
51 | * @var FilesystemInterface |
||
52 | */ |
||
53 | protected $filesystem; |
||
54 | |||
55 | /** |
||
56 | * @var AdapterInterface |
||
57 | */ |
||
58 | protected $adapter; |
||
59 | |||
60 | /** |
||
61 | * @var string |
||
62 | */ |
||
63 | protected $entryPath; |
||
64 | |||
65 | /** |
||
66 | * FlysystemDriver constructor. |
||
67 | * @param array $configuration |
||
68 | */ |
||
69 | 66 | public function __construct(array $configuration = []) |
|
78 | |||
79 | /** |
||
80 | * Processes the configuration for this driver. |
||
81 | * @return void |
||
82 | */ |
||
83 | public function processConfiguration() |
||
87 | |||
88 | /** |
||
89 | * Merges the capabilities merged by the user at the storage |
||
90 | * configuration into the actual capabilities of the driver |
||
91 | * and returns the result. |
||
92 | * |
||
93 | * @param int $capabilities |
||
94 | * @return int |
||
95 | */ |
||
96 | public function mergeConfigurationCapabilities($capabilities) |
||
101 | |||
102 | /** |
||
103 | * Returns the identifier of the root level folder of the storage. |
||
104 | * |
||
105 | * @return string |
||
106 | */ |
||
107 | public function getRootLevelFolder() |
||
111 | |||
112 | /** |
||
113 | * Returns the identifier of the default folder new files should be put into. |
||
114 | * |
||
115 | * @return string |
||
116 | */ |
||
117 | 3 | public function getDefaultFolder() |
|
126 | |||
127 | /** |
||
128 | * Checks if a folder exists. |
||
129 | * |
||
130 | * @param string $folderIdentifier |
||
131 | * @return bool |
||
132 | */ |
||
133 | 9 | public function folderExists($folderIdentifier) |
|
147 | |||
148 | /** |
||
149 | * Creates a folder, within a parent folder. |
||
150 | * If no parent folder is given, a root level folder will be created |
||
151 | * |
||
152 | * @param string $newFolderName |
||
153 | * @param string $parentFolderIdentifier |
||
154 | * @param bool $recursive |
||
155 | * @return string the Identifier of the new folder |
||
156 | */ |
||
157 | 9 | public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false) |
|
168 | |||
169 | /** |
||
170 | * Returns the public URL to a file. |
||
171 | * Either fully qualified URL or relative to PATH_site (rawurlencoded). |
||
172 | * |
||
173 | * @param string $identifier |
||
174 | * @return string |
||
175 | */ |
||
176 | public function getPublicUrl($identifier) |
||
180 | |||
181 | /** |
||
182 | * Renames a folder in this storage. |
||
183 | * |
||
184 | * @param string $folderIdentifier |
||
185 | * @param string $newName |
||
186 | * @return array A map of old to new file identifiers of all affected resources |
||
187 | */ |
||
188 | 3 | public function renameFolder($folderIdentifier, $newName) |
|
198 | |||
199 | /** |
||
200 | * Removes a folder in filesystem. |
||
201 | * |
||
202 | * @param string $folderIdentifier |
||
203 | * @param bool $deleteRecursively |
||
204 | * @return bool |
||
205 | * @throws FileOperationErrorException |
||
206 | */ |
||
207 | public function deleteFolder($folderIdentifier, $deleteRecursively = false) |
||
219 | |||
220 | /** |
||
221 | * Checks if a file exists. |
||
222 | * |
||
223 | * @param string $fileIdentifier |
||
224 | * @return bool |
||
225 | */ |
||
226 | 18 | public function fileExists($fileIdentifier) |
|
233 | |||
234 | /** |
||
235 | * Checks if a folder contains files and (if supported) other folders. |
||
236 | * |
||
237 | * @param string $folderIdentifier |
||
238 | * @return bool TRUE if there are no files and folders within $folder |
||
239 | */ |
||
240 | 3 | public function isFolderEmpty($folderIdentifier) |
|
244 | |||
245 | /** |
||
246 | * Adds a file from the local server hard disk to a given path in TYPO3s |
||
247 | * virtual file system. This assumes that the local file exists, so no |
||
248 | * further check is done here! After a successful the original file must |
||
249 | * not exist anymore. |
||
250 | * |
||
251 | * @param string $localFilePath (within PATH_site) |
||
252 | * @param string $targetFolderIdentifier |
||
253 | * @param string $newFileName optional, if not given original name is used |
||
254 | * @param bool $removeOriginal if set the original file will be removed |
||
255 | * after successful operation |
||
256 | * @return string the identifier of the new file |
||
257 | */ |
||
258 | 3 | public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true) |
|
284 | |||
285 | /** |
||
286 | * Creates a new (empty) file and returns the identifier. |
||
287 | * |
||
288 | * @param string $fileName |
||
289 | * @param string $parentFolderIdentifier |
||
290 | * @return string |
||
291 | * @throws InvalidFileNameException |
||
292 | */ |
||
293 | 3 | public function createFile($fileName, $parentFolderIdentifier) |
|
316 | |||
317 | /** |
||
318 | * Copies a file *within* the current storage. |
||
319 | * Note that this is only about an inner storage copy action, |
||
320 | * where a file is just copied to another folder in the same storage. |
||
321 | * |
||
322 | * @param string $fileIdentifier |
||
323 | * @param string $targetFolderIdentifier |
||
324 | * @param string $fileName |
||
325 | * @return string the Identifier of the new file |
||
326 | */ |
||
327 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
336 | |||
337 | /** |
||
338 | * Renames a file in this storage. |
||
339 | * |
||
340 | * @param string $fileIdentifier |
||
341 | * @param string $newName The target path (including the file name!) |
||
342 | * @return string The identifier of the file after renaming |
||
343 | * @throws ExistingTargetFileNameException |
||
344 | */ |
||
345 | 6 | public function renameFile($fileIdentifier, $newName) |
|
367 | |||
368 | /** |
||
369 | * Replaces a file with file in local file system. |
||
370 | * |
||
371 | * @param string $fileIdentifier |
||
372 | * @param string $localFilePath |
||
373 | * @return bool TRUE if the operation succeeded |
||
374 | */ |
||
375 | public function replaceFile($fileIdentifier, $localFilePath) |
||
383 | |||
384 | /** |
||
385 | * Removes a file from the filesystem. This does not check if the file is |
||
386 | * still used or if it is a bad idea to delete it for some other reason |
||
387 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
388 | * |
||
389 | * @param string $fileIdentifier |
||
390 | * @return bool TRUE if deleting the file succeeded |
||
391 | */ |
||
392 | 3 | public function deleteFile($fileIdentifier) |
|
396 | |||
397 | /** |
||
398 | * Creates a hash for a file. |
||
399 | * |
||
400 | * @param string $fileIdentifier |
||
401 | * @param string $hashAlgorithm The hash algorithm to use |
||
402 | * @return string |
||
403 | */ |
||
404 | 9 | public function hash($fileIdentifier, $hashAlgorithm) |
|
425 | |||
426 | /** |
||
427 | * Moves a file *within* the current storage. |
||
428 | * Note that this is only about an inner-storage move action, |
||
429 | * where a file is just moved to another folder in the same storage. |
||
430 | * |
||
431 | * @param string $fileIdentifier |
||
432 | * @param string $targetFolderIdentifier |
||
433 | * @param string $newFileName |
||
434 | * @return string |
||
435 | */ |
||
436 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
||
440 | |||
441 | /** |
||
442 | * Folder equivalent to moveFileWithinStorage(). |
||
443 | * |
||
444 | * @param string $sourceFolderIdentifier |
||
445 | * @param string $targetFolderIdentifier |
||
446 | * @param string $newFolderName |
||
447 | * @return array All files which are affected, map of old => new file identifiers |
||
448 | */ |
||
449 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
453 | |||
454 | /** |
||
455 | * Folder equivalent to copyFileWithinStorage(). |
||
456 | * |
||
457 | * @param string $sourceFolderIdentifier |
||
458 | * @param string $targetFolderIdentifier |
||
459 | * @param string $newFolderName |
||
460 | * @return bool |
||
461 | */ |
||
462 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
466 | |||
467 | /** |
||
468 | * Returns the contents of a file. Beware that this requires to load the |
||
469 | * complete file into memory and also may require fetching the file from an |
||
470 | * external location. So this might be an expensive operation (both in terms |
||
471 | * of processing resources and money) for large files. |
||
472 | * |
||
473 | * @param string $fileIdentifier |
||
474 | * @return string The file contents |
||
475 | */ |
||
476 | 3 | public function getFileContents($fileIdentifier) |
|
480 | |||
481 | /** |
||
482 | * Sets the contents of a file to the specified value. |
||
483 | * |
||
484 | * @param string $fileIdentifier |
||
485 | * @param string $contents |
||
486 | * @return int The number of bytes written to the file |
||
487 | */ |
||
488 | 3 | public function setFileContents($fileIdentifier, $contents) |
|
494 | |||
495 | /** |
||
496 | * Checks if a file inside a folder exists |
||
497 | * |
||
498 | * @param string $fileName |
||
499 | * @param string $folderIdentifier |
||
500 | * @return bool |
||
501 | */ |
||
502 | 3 | public function fileExistsInFolder($fileName, $folderIdentifier) |
|
508 | |||
509 | /** |
||
510 | * Checks if a folder inside a folder exists. |
||
511 | * |
||
512 | * @param string $folderName |
||
513 | * @param string $folderIdentifier |
||
514 | * @return bool |
||
515 | */ |
||
516 | 3 | public function folderExistsInFolder($folderName, $folderIdentifier) |
|
522 | |||
523 | /** |
||
524 | * Returns a path to a local copy of a file for processing it. When changing the |
||
525 | * file, you have to take care of replacing the current version yourself! |
||
526 | * |
||
527 | * @param string $fileIdentifier |
||
528 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
529 | * operations. This might speed up things, e.g. by using |
||
530 | * a cached local version. Never modify the file if you |
||
531 | * have set this flag! |
||
532 | * @return string The path to the file on the local disk |
||
533 | */ |
||
534 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
542 | |||
543 | /** |
||
544 | * Returns the permissions of a file/folder as an array |
||
545 | * (keys r, w) of boolean flags |
||
546 | * |
||
547 | * @param string $identifier |
||
548 | * @return array |
||
549 | */ |
||
550 | public function getPermissions($identifier) |
||
557 | |||
558 | /** |
||
559 | * Directly output the contents of the file to the output |
||
560 | * buffer. Should not take care of header files or flushing |
||
561 | * buffer before. Will be taken care of by the Storage. |
||
562 | * |
||
563 | * @param string $identifier |
||
564 | * @return void |
||
565 | */ |
||
566 | public function dumpFileContents($identifier) |
||
573 | |||
574 | /** |
||
575 | * Checks if a given identifier is within a container, e.g. if |
||
576 | * a file or folder is within another folder. |
||
577 | * This can e.g. be used to check for web-mounts. |
||
578 | * |
||
579 | * Hint: this also needs to return TRUE if the given identifier |
||
580 | * matches the container identifier to allow access to the root |
||
581 | * folder of a filemount. |
||
582 | * |
||
583 | * @param string $folderIdentifier |
||
584 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
585 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
586 | */ |
||
587 | public function isWithin($folderIdentifier, $identifier) |
||
601 | |||
602 | /** |
||
603 | * Returns information about a file. |
||
604 | * |
||
605 | * @param string $fileIdentifier |
||
606 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
607 | * If empty all will be extracted |
||
608 | * @return array |
||
609 | * @throws FileDoesNotExistException |
||
610 | */ |
||
611 | 6 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []) |
|
621 | |||
622 | /** |
||
623 | * Returns information about a file. |
||
624 | * |
||
625 | * @param string $folderIdentifier |
||
626 | * @return array |
||
627 | * @throws FolderDoesNotExistException |
||
628 | */ |
||
629 | 3 | public function getFolderInfoByIdentifier($folderIdentifier) |
|
645 | |||
646 | /** |
||
647 | * Returns the identifier of a file inside the folder |
||
648 | * |
||
649 | * @param string $fileName |
||
650 | * @param string $folderIdentifier |
||
651 | * @return string file identifier |
||
652 | */ |
||
653 | public function getFileInFolder($fileName, $folderIdentifier) |
||
657 | |||
658 | /** |
||
659 | * Returns a list of files inside the specified path |
||
660 | * |
||
661 | * @param string $folderIdentifier |
||
662 | * @param int $start |
||
663 | * @param int $numberOfItems |
||
664 | * @param bool $recursive |
||
665 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
666 | * @param string $sort Property name used to sort the items. |
||
667 | * Among them may be: '' (empty, no sorting), name, |
||
668 | * fileext, size, tstamp and rw. |
||
669 | * If a driver does not support the given property, it |
||
670 | * should fall back to "name". |
||
671 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
672 | * @return array of FileIdentifiers |
||
673 | */ |
||
674 | 3 | public function getFilesInFolder( |
|
698 | |||
699 | /** |
||
700 | * Returns the identifier of a folder inside the folder |
||
701 | * |
||
702 | * @param string $folderName The name of the target folder |
||
703 | * @param string $folderIdentifier |
||
704 | * @return string folder identifier |
||
705 | */ |
||
706 | 3 | public function getFolderInFolder($folderName, $folderIdentifier) |
|
711 | |||
712 | /** |
||
713 | * Returns a list of folders inside the specified path |
||
714 | * |
||
715 | * @param string $folderIdentifier |
||
716 | * @param int $start |
||
717 | * @param int $numberOfItems |
||
718 | * @param bool $recursive |
||
719 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
720 | * @param string $sort Property name used to sort the items. |
||
721 | * Among them may be: '' (empty, no sorting), name, |
||
722 | * fileext, size, tstamp and rw. |
||
723 | * If a driver does not support the given property, it |
||
724 | * should fall back to "name". |
||
725 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
726 | * @return array of Folder Identifier |
||
727 | * @TODO: Implement pagination with $start and $numberOfItems |
||
728 | * @TODO: Implement directory filter callbacks |
||
729 | * @TODO: Implement sorting |
||
730 | */ |
||
731 | 3 | public function getFoldersInFolder( |
|
756 | |||
757 | /** |
||
758 | * Returns the number of files inside the specified path |
||
759 | * |
||
760 | * @param string $folderIdentifier |
||
761 | * @param bool $recursive |
||
762 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
763 | * @return int Number of files in folder |
||
764 | * @TODO: Implement recursive count |
||
765 | * @TODO: Implement filename filtering |
||
766 | */ |
||
767 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []) |
||
772 | |||
773 | /** |
||
774 | * Returns the number of folders inside the specified path |
||
775 | * |
||
776 | * @param string $folderIdentifier |
||
777 | * @param bool $recursive |
||
778 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
779 | * @return int Number of folders in folder |
||
780 | */ |
||
781 | 3 | public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []) |
|
794 | |||
795 | /** |
||
796 | * Extracts information about a file from the filesystem. |
||
797 | * |
||
798 | * @param string $filePath The absolute path to the file |
||
799 | * @param string $containerPath The relative path to the file's container |
||
800 | * @param array $propertiesToExtract array of properties which should be returned, if empty all will be extracted |
||
801 | * @return array |
||
802 | */ |
||
803 | 6 | protected function extractFileInformation($filePath, $containerPath, array $propertiesToExtract = array()) |
|
826 | |||
827 | /** |
||
828 | * Extracts a specific FileInformation from the FileSystems. |
||
829 | * |
||
830 | * @param string $fileIdentifier |
||
831 | * @param string $containerPath |
||
832 | * @param string $property |
||
833 | * |
||
834 | * @return bool|int|string |
||
835 | * @throws \InvalidArgumentException |
||
836 | */ |
||
837 | 6 | public function getSpecificFileInformation($fileIdentifier, $containerPath, $property) |
|
867 | } |
||
868 |