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) |
|
| 280 | |||
| 281 | /** |
||
| 282 | * Creates a new (empty) file and returns the identifier. |
||
| 283 | * |
||
| 284 | * @param string $fileName |
||
| 285 | * @param string $parentFolderIdentifier |
||
| 286 | * @return string |
||
| 287 | * @throws InvalidFileNameException |
||
| 288 | */ |
||
| 289 | 3 | public function createFile($fileName, $parentFolderIdentifier) |
|
| 312 | |||
| 313 | /** |
||
| 314 | * Copies a file *within* the current storage. |
||
| 315 | * Note that this is only about an inner storage copy action, |
||
| 316 | * where a file is just copied to another folder in the same storage. |
||
| 317 | * |
||
| 318 | * @param string $fileIdentifier |
||
| 319 | * @param string $targetFolderIdentifier |
||
| 320 | * @param string $fileName |
||
| 321 | * @return string the Identifier of the new file |
||
| 322 | */ |
||
| 323 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
| 332 | |||
| 333 | /** |
||
| 334 | * Renames a file in this storage. |
||
| 335 | * |
||
| 336 | * @param string $fileIdentifier |
||
| 337 | * @param string $newName The target path (including the file name!) |
||
| 338 | * @return string The identifier of the file after renaming |
||
| 339 | * @throws ExistingTargetFileNameException |
||
| 340 | */ |
||
| 341 | 6 | public function renameFile($fileIdentifier, $newName) |
|
| 363 | |||
| 364 | /** |
||
| 365 | * Replaces a file with file in local file system. |
||
| 366 | * |
||
| 367 | * @param string $fileIdentifier |
||
| 368 | * @param string $localFilePath |
||
| 369 | * @return bool TRUE if the operation succeeded |
||
| 370 | */ |
||
| 371 | public function replaceFile($fileIdentifier, $localFilePath) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Removes a file from the filesystem. This does not check if the file is |
||
| 382 | * still used or if it is a bad idea to delete it for some other reason |
||
| 383 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
| 384 | * |
||
| 385 | * @param string $fileIdentifier |
||
| 386 | * @return bool TRUE if deleting the file succeeded |
||
| 387 | */ |
||
| 388 | 3 | public function deleteFile($fileIdentifier) |
|
| 392 | |||
| 393 | /** |
||
| 394 | * Creates a hash for a file. |
||
| 395 | * |
||
| 396 | * @param string $fileIdentifier |
||
| 397 | * @param string $hashAlgorithm The hash algorithm to use |
||
| 398 | * @return string |
||
| 399 | */ |
||
| 400 | 9 | public function hash($fileIdentifier, $hashAlgorithm) |
|
| 421 | |||
| 422 | /** |
||
| 423 | * Moves a file *within* the current storage. |
||
| 424 | * Note that this is only about an inner-storage move action, |
||
| 425 | * where a file is just moved to another folder in the same storage. |
||
| 426 | * |
||
| 427 | * @param string $fileIdentifier |
||
| 428 | * @param string $targetFolderIdentifier |
||
| 429 | * @param string $newFileName |
||
| 430 | * @return string |
||
| 431 | */ |
||
| 432 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
||
| 436 | |||
| 437 | /** |
||
| 438 | * Folder equivalent to moveFileWithinStorage(). |
||
| 439 | * |
||
| 440 | * @param string $sourceFolderIdentifier |
||
| 441 | * @param string $targetFolderIdentifier |
||
| 442 | * @param string $newFolderName |
||
| 443 | * @return array All files which are affected, map of old => new file identifiers |
||
| 444 | */ |
||
| 445 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 449 | |||
| 450 | /** |
||
| 451 | * Folder equivalent to copyFileWithinStorage(). |
||
| 452 | * |
||
| 453 | * @param string $sourceFolderIdentifier |
||
| 454 | * @param string $targetFolderIdentifier |
||
| 455 | * @param string $newFolderName |
||
| 456 | * @return bool |
||
| 457 | */ |
||
| 458 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 462 | |||
| 463 | /** |
||
| 464 | * Returns the contents of a file. Beware that this requires to load the |
||
| 465 | * complete file into memory and also may require fetching the file from an |
||
| 466 | * external location. So this might be an expensive operation (both in terms |
||
| 467 | * of processing resources and money) for large files. |
||
| 468 | * |
||
| 469 | * @param string $fileIdentifier |
||
| 470 | * @return string The file contents |
||
| 471 | */ |
||
| 472 | 3 | public function getFileContents($fileIdentifier) |
|
| 476 | |||
| 477 | /** |
||
| 478 | * Sets the contents of a file to the specified value. |
||
| 479 | * |
||
| 480 | * @param string $fileIdentifier |
||
| 481 | * @param string $contents |
||
| 482 | * @return int The number of bytes written to the file |
||
| 483 | */ |
||
| 484 | 3 | public function setFileContents($fileIdentifier, $contents) |
|
| 490 | |||
| 491 | /** |
||
| 492 | * Checks if a file inside a folder exists |
||
| 493 | * |
||
| 494 | * @param string $fileName |
||
| 495 | * @param string $folderIdentifier |
||
| 496 | * @return bool |
||
| 497 | */ |
||
| 498 | 3 | public function fileExistsInFolder($fileName, $folderIdentifier) |
|
| 504 | |||
| 505 | /** |
||
| 506 | * Checks if a folder inside a folder exists. |
||
| 507 | * |
||
| 508 | * @param string $folderName |
||
| 509 | * @param string $folderIdentifier |
||
| 510 | * @return bool |
||
| 511 | */ |
||
| 512 | 3 | public function folderExistsInFolder($folderName, $folderIdentifier) |
|
| 518 | |||
| 519 | /** |
||
| 520 | * Returns a path to a local copy of a file for processing it. When changing the |
||
| 521 | * file, you have to take care of replacing the current version yourself! |
||
| 522 | * |
||
| 523 | * @param string $fileIdentifier |
||
| 524 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
| 525 | * operations. This might speed up things, e.g. by using |
||
| 526 | * a cached local version. Never modify the file if you |
||
| 527 | * have set this flag! |
||
| 528 | * @return string The path to the file on the local disk |
||
| 529 | */ |
||
| 530 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * Returns the permissions of a file/folder as an array |
||
| 537 | * (keys r, w) of boolean flags |
||
| 538 | * |
||
| 539 | * @param string $identifier |
||
| 540 | * @return array |
||
| 541 | */ |
||
| 542 | public function getPermissions($identifier) |
||
| 549 | |||
| 550 | /** |
||
| 551 | * Directly output the contents of the file to the output |
||
| 552 | * buffer. Should not take care of header files or flushing |
||
| 553 | * buffer before. Will be taken care of by the Storage. |
||
| 554 | * |
||
| 555 | * @param string $identifier |
||
| 556 | * @return void |
||
| 557 | */ |
||
| 558 | public function dumpFileContents($identifier) |
||
| 565 | |||
| 566 | /** |
||
| 567 | * Checks if a given identifier is within a container, e.g. if |
||
| 568 | * a file or folder is within another folder. |
||
| 569 | * This can e.g. be used to check for web-mounts. |
||
| 570 | * |
||
| 571 | * Hint: this also needs to return TRUE if the given identifier |
||
| 572 | * matches the container identifier to allow access to the root |
||
| 573 | * folder of a filemount. |
||
| 574 | * |
||
| 575 | * @param string $folderIdentifier |
||
| 576 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
| 577 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
| 578 | */ |
||
| 579 | public function isWithin($folderIdentifier, $identifier) |
||
| 593 | |||
| 594 | /** |
||
| 595 | * Returns information about a file. |
||
| 596 | * |
||
| 597 | * @param string $fileIdentifier |
||
| 598 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
| 599 | * If empty all will be extracted |
||
| 600 | * @return array |
||
| 601 | * @throws FileDoesNotExistException |
||
| 602 | */ |
||
| 603 | 6 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []) |
|
| 613 | |||
| 614 | /** |
||
| 615 | * Returns information about a file. |
||
| 616 | * |
||
| 617 | * @param string $folderIdentifier |
||
| 618 | * @return array |
||
| 619 | * @throws FolderDoesNotExistException |
||
| 620 | */ |
||
| 621 | 3 | public function getFolderInfoByIdentifier($folderIdentifier) |
|
| 637 | |||
| 638 | /** |
||
| 639 | * Returns the identifier of a file inside the folder |
||
| 640 | * |
||
| 641 | * @param string $fileName |
||
| 642 | * @param string $folderIdentifier |
||
| 643 | * @return string file identifier |
||
| 644 | */ |
||
| 645 | public function getFileInFolder($fileName, $folderIdentifier) |
||
| 649 | |||
| 650 | /** |
||
| 651 | * Returns a list of files inside the specified path |
||
| 652 | * |
||
| 653 | * @param string $folderIdentifier |
||
| 654 | * @param int $start |
||
| 655 | * @param int $numberOfItems |
||
| 656 | * @param bool $recursive |
||
| 657 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 658 | * @param string $sort Property name used to sort the items. |
||
| 659 | * Among them may be: '' (empty, no sorting), name, |
||
| 660 | * fileext, size, tstamp and rw. |
||
| 661 | * If a driver does not support the given property, it |
||
| 662 | * should fall back to "name". |
||
| 663 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 664 | * @return array of FileIdentifiers |
||
| 665 | */ |
||
| 666 | 3 | public function getFilesInFolder( |
|
| 690 | |||
| 691 | /** |
||
| 692 | * Returns the identifier of a folder inside the folder |
||
| 693 | * |
||
| 694 | * @param string $folderName The name of the target folder |
||
| 695 | * @param string $folderIdentifier |
||
| 696 | * @return string folder identifier |
||
| 697 | */ |
||
| 698 | 3 | public function getFolderInFolder($folderName, $folderIdentifier) |
|
| 703 | |||
| 704 | /** |
||
| 705 | * Returns a list of folders inside the specified path |
||
| 706 | * |
||
| 707 | * @param string $folderIdentifier |
||
| 708 | * @param int $start |
||
| 709 | * @param int $numberOfItems |
||
| 710 | * @param bool $recursive |
||
| 711 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 712 | * @param string $sort Property name used to sort the items. |
||
| 713 | * Among them may be: '' (empty, no sorting), name, |
||
| 714 | * fileext, size, tstamp and rw. |
||
| 715 | * If a driver does not support the given property, it |
||
| 716 | * should fall back to "name". |
||
| 717 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 718 | * @return array of Folder Identifier |
||
| 719 | * @TODO: Implement pagination with $start and $numberOfItems |
||
| 720 | * @TODO: Implement directory filter callbacks |
||
| 721 | * @TODO: Implement sorting |
||
| 722 | */ |
||
| 723 | 3 | public function getFoldersInFolder( |
|
| 748 | |||
| 749 | /** |
||
| 750 | * Returns the number of files inside the specified path |
||
| 751 | * |
||
| 752 | * @param string $folderIdentifier |
||
| 753 | * @param bool $recursive |
||
| 754 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 755 | * @return int Number of files in folder |
||
| 756 | * @TODO: Implement recursive count |
||
| 757 | * @TODO: Implement filename filtering |
||
| 758 | */ |
||
| 759 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []) |
||
| 764 | |||
| 765 | /** |
||
| 766 | * Returns the number of folders inside the specified path |
||
| 767 | * |
||
| 768 | * @param string $folderIdentifier |
||
| 769 | * @param bool $recursive |
||
| 770 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 771 | * @return int Number of folders in folder |
||
| 772 | */ |
||
| 773 | 3 | public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []) |
|
| 786 | |||
| 787 | /** |
||
| 788 | * Extracts information about a file from the filesystem. |
||
| 789 | * |
||
| 790 | * @param string $filePath The absolute path to the file |
||
| 791 | * @param string $containerPath The relative path to the file's container |
||
| 792 | * @param array $propertiesToExtract array of properties which should be returned, if empty all will be extracted |
||
| 793 | * @return array |
||
| 794 | */ |
||
| 795 | 6 | protected function extractFileInformation($filePath, $containerPath, array $propertiesToExtract = array()) |
|
| 818 | |||
| 819 | /** |
||
| 820 | * Extracts a specific FileInformation from the FileSystems. |
||
| 821 | * |
||
| 822 | * @param string $fileIdentifier |
||
| 823 | * @param string $containerPath |
||
| 824 | * @param string $property |
||
| 825 | * |
||
| 826 | * @return bool|int|string |
||
| 827 | * @throws \InvalidArgumentException |
||
| 828 | */ |
||
| 829 | 6 | public function getSpecificFileInformation($fileIdentifier, $containerPath, $property) |
|
| 859 | |||
| 860 | /** |
||
| 861 | * Copies a file to a temporary path and returns that path. |
||
| 862 | * |
||
| 863 | * @param string $fileIdentifier |
||
| 864 | * @return string The temporary path |
||
| 865 | * @throws \RuntimeException |
||
| 866 | */ |
||
| 867 | protected function copyFileToTemporaryPath($fileIdentifier) |
||
| 884 | } |
||
| 885 |