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 |
||
| 38 | abstract class FlysystemDriver extends AbstractHierarchicalFilesystemDriver |
||
| 39 | { |
||
| 40 | /** |
||
| 41 | * @var FilesystemInterface |
||
| 42 | */ |
||
| 43 | 51 | protected $filesystem; |
|
| 44 | |||
| 45 | 51 | /** |
|
| 46 | * @var AdapterInterface |
||
| 47 | 51 | */ |
|
| 48 | 17 | protected $adapter; |
|
| 49 | 51 | ||
| 50 | 51 | /** |
|
| 51 | 51 | * @var string |
|
| 52 | */ |
||
| 53 | protected $entryPath; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * FlysystemDriver constructor. |
||
| 57 | * @param array $configuration |
||
| 58 | */ |
||
| 59 | public function __construct(array $configuration = []) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * Processes the configuration for this driver. |
||
| 71 | * @return void |
||
| 72 | */ |
||
| 73 | public function processConfiguration() |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Merges the capabilities merged by the user at the storage |
||
| 80 | * configuration into the actual capabilities of the driver |
||
| 81 | * and returns the result. |
||
| 82 | * |
||
| 83 | * @param int $capabilities |
||
| 84 | * @return int |
||
| 85 | */ |
||
| 86 | public function mergeConfigurationCapabilities($capabilities) |
||
| 91 | |||
| 92 | 3 | /** |
|
| 93 | 3 | * Returns the identifier of the root level folder of the storage. |
|
| 94 | 3 | * |
|
| 95 | 3 | * @return string |
|
| 96 | 2 | */ |
|
| 97 | 3 | public function getRootLevelFolder() |
|
| 101 | |||
| 102 | /** |
||
| 103 | * Returns the identifier of the default folder new files should be put into. |
||
| 104 | * |
||
| 105 | * @return string |
||
| 106 | 6 | */ |
|
| 107 | public function getDefaultFolder() |
||
| 116 | |||
| 117 | /** |
||
| 118 | * Checks if a folder exists. |
||
| 119 | * |
||
| 120 | * @param string $folderIdentifier |
||
| 121 | * @return bool |
||
| 122 | */ |
||
| 123 | public function folderExists($folderIdentifier) |
||
| 137 | |||
| 138 | /** |
||
| 139 | * Creates a folder, within a parent folder. |
||
| 140 | * If no parent folder is given, a root level folder will be created |
||
| 141 | * |
||
| 142 | * @param string $newFolderName |
||
| 143 | * @param string $parentFolderIdentifier |
||
| 144 | * @param bool $recursive |
||
| 145 | * @return string the Identifier of the new folder |
||
| 146 | */ |
||
| 147 | public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false) |
||
| 158 | |||
| 159 | 3 | /** |
|
| 160 | 3 | * Returns the public URL to a file. |
|
| 161 | * Either fully qualified URL or relative to PATH_site (rawurlencoded). |
||
| 162 | * |
||
| 163 | * @param string $identifier |
||
| 164 | * @return string |
||
| 165 | */ |
||
| 166 | public function getPublicUrl($identifier) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * Renames a folder in this storage. |
||
| 173 | * |
||
| 174 | * @param string $folderIdentifier |
||
| 175 | * @param string $newName |
||
| 176 | * @return array A map of old to new file identifiers of all affected resources |
||
| 177 | */ |
||
| 178 | public function renameFolder($folderIdentifier, $newName) |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Removes a folder in filesystem. |
||
| 191 | * |
||
| 192 | * @param string $folderIdentifier |
||
| 193 | 12 | * @param bool $deleteRecursively |
|
| 194 | * @return bool |
||
| 195 | 12 | * @throws FileOperationErrorException |
|
| 196 | 12 | */ |
|
| 197 | public function deleteFolder($folderIdentifier, $deleteRecursively = false) |
||
| 209 | 3 | ||
| 210 | /** |
||
| 211 | * Checks if a file exists. |
||
| 212 | * |
||
| 213 | * @param string $fileIdentifier |
||
| 214 | * @return bool |
||
| 215 | */ |
||
| 216 | public function fileExists($fileIdentifier) |
||
| 223 | |||
| 224 | /** |
||
| 225 | 3 | * Checks if a folder contains files and (if supported) other folders. |
|
| 226 | * |
||
| 227 | 3 | * @param string $folderIdentifier |
|
| 228 | 3 | * @return bool TRUE if there are no files and folders within $folder |
|
| 229 | 3 | */ |
|
| 230 | public function isFolderEmpty($folderIdentifier) |
||
| 234 | |||
| 235 | 3 | /** |
|
| 236 | * Adds a file from the local server hard disk to a given path in TYPO3s |
||
| 237 | * virtual file system. This assumes that the local file exists, so no |
||
| 238 | * further check is done here! After a successful the original file must |
||
| 239 | * not exist anymore. |
||
| 240 | * |
||
| 241 | * @param string $localFilePath (within PATH_site) |
||
| 242 | * @param string $targetFolderIdentifier |
||
| 243 | 3 | * @param string $newFileName optional, if not given original name is used |
|
| 244 | * @param bool $removeOriginal if set the original file will be removed |
||
| 245 | 3 | * after successful operation |
|
| 246 | * @return string the identifier of the new file |
||
| 247 | */ |
||
| 248 | 3 | public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true) |
|
| 274 | 3 | ||
| 275 | 3 | /** |
|
| 276 | * Creates a new (empty) file and returns the identifier. |
||
| 277 | 3 | * |
|
| 278 | * @param string $fileName |
||
| 279 | * @param string $parentFolderIdentifier |
||
| 280 | * @return string |
||
| 281 | 3 | * @throws InvalidFileNameException |
|
| 282 | */ |
||
| 283 | public function createFile($fileName, $parentFolderIdentifier) |
||
| 306 | |||
| 307 | /** |
||
| 308 | * Copies a file *within* the current storage. |
||
| 309 | * Note that this is only about an inner storage copy action, |
||
| 310 | * where a file is just copied to another folder in the same storage. |
||
| 311 | * |
||
| 312 | * @param string $fileIdentifier |
||
| 313 | * @param string $targetFolderIdentifier |
||
| 314 | * @param string $fileName |
||
| 315 | * @return string the Identifier of the new file |
||
| 316 | */ |
||
| 317 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Renames a file in this storage. |
||
| 329 | * |
||
| 330 | * @param string $fileIdentifier |
||
| 331 | * @param string $newName The target path (including the file name!) |
||
| 332 | * @return string The identifier of the file after renaming |
||
| 333 | */ |
||
| 334 | public function renameFile($fileIdentifier, $newName) |
||
| 342 | |||
| 343 | /** |
||
| 344 | 3 | * Replaces a file with file in local file system. |
|
| 345 | * |
||
| 346 | 3 | * @param string $fileIdentifier |
|
| 347 | * @param string $localFilePath |
||
| 348 | * @return bool TRUE if the operation succeeded |
||
| 349 | */ |
||
| 350 | public function replaceFile($fileIdentifier, $localFilePath) |
||
| 358 | |||
| 359 | /** |
||
| 360 | * Removes a file from the filesystem. This does not check if the file is |
||
| 361 | * still used or if it is a bad idea to delete it for some other reason |
||
| 362 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
| 363 | * |
||
| 364 | * @param string $fileIdentifier |
||
| 365 | * @return bool TRUE if deleting the file succeeded |
||
| 366 | */ |
||
| 367 | public function deleteFile($fileIdentifier) |
||
| 371 | |||
| 372 | /** |
||
| 373 | * Creates a hash for a file. |
||
| 374 | * |
||
| 375 | * @param string $fileIdentifier |
||
| 376 | * @param string $hashAlgorithm The hash algorithm to use |
||
| 377 | * @return string |
||
| 378 | */ |
||
| 379 | public function hash($fileIdentifier, $hashAlgorithm) |
||
| 400 | |||
| 401 | /** |
||
| 402 | * Moves a file *within* the current storage. |
||
| 403 | * Note that this is only about an inner-storage move action, |
||
| 404 | * where a file is just moved to another folder in the same storage. |
||
| 405 | * |
||
| 406 | * @param string $fileIdentifier |
||
| 407 | * @param string $targetFolderIdentifier |
||
| 408 | * @param string $newFileName |
||
| 409 | * @return string |
||
| 410 | */ |
||
| 411 | 3 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Folder equivalent to moveFileWithinStorage(). |
||
| 418 | * |
||
| 419 | * @param string $sourceFolderIdentifier |
||
| 420 | * @param string $targetFolderIdentifier |
||
| 421 | * @param string $newFolderName |
||
| 422 | * @return array All files which are affected, map of old => new file identifiers |
||
| 423 | 3 | */ |
|
| 424 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 428 | |||
| 429 | /** |
||
| 430 | * Folder equivalent to copyFileWithinStorage(). |
||
| 431 | * |
||
| 432 | * @param string $sourceFolderIdentifier |
||
| 433 | * @param string $targetFolderIdentifier |
||
| 434 | * @param string $newFolderName |
||
| 435 | * @return bool |
||
| 436 | */ |
||
| 437 | 3 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
|
| 441 | 3 | ||
| 442 | /** |
||
| 443 | * Returns the contents of a file. Beware that this requires to load the |
||
| 444 | * complete file into memory and also may require fetching the file from an |
||
| 445 | * external location. So this might be an expensive operation (both in terms |
||
| 446 | * of processing resources and money) for large files. |
||
| 447 | * |
||
| 448 | * @param string $fileIdentifier |
||
| 449 | * @return string The file contents |
||
| 450 | */ |
||
| 451 | 3 | public function getFileContents($fileIdentifier) |
|
| 455 | 3 | ||
| 456 | /** |
||
| 457 | * Sets the contents of a file to the specified value. |
||
| 458 | * |
||
| 459 | * @param string $fileIdentifier |
||
| 460 | * @param string $contents |
||
| 461 | * @return int The number of bytes written to the file |
||
| 462 | */ |
||
| 463 | public function setFileContents($fileIdentifier, $contents) |
||
| 469 | |||
| 470 | /** |
||
| 471 | * Checks if a file inside a folder exists |
||
| 472 | * |
||
| 473 | * @param string $fileName |
||
| 474 | * @param string $folderIdentifier |
||
| 475 | * @return bool |
||
| 476 | */ |
||
| 477 | public function fileExistsInFolder($fileName, $folderIdentifier) |
||
| 483 | |||
| 484 | /** |
||
| 485 | * Checks if a folder inside a folder exists. |
||
| 486 | * |
||
| 487 | * @param string $folderName |
||
| 488 | * @param string $folderIdentifier |
||
| 489 | * @return bool |
||
| 490 | */ |
||
| 491 | public function folderExistsInFolder($folderName, $folderIdentifier) |
||
| 497 | |||
| 498 | /** |
||
| 499 | * Returns a path to a local copy of a file for processing it. When changing the |
||
| 500 | * file, you have to take care of replacing the current version yourself! |
||
| 501 | * |
||
| 502 | * @param string $fileIdentifier |
||
| 503 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
| 504 | * operations. This might speed up things, e.g. by using |
||
| 505 | * a cached local version. Never modify the file if you |
||
| 506 | * have set this flag! |
||
| 507 | * @return string The path to the file on the local disk |
||
| 508 | */ |
||
| 509 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
| 517 | |||
| 518 | /** |
||
| 519 | * Returns the permissions of a file/folder as an array |
||
| 520 | * (keys r, w) of boolean flags |
||
| 521 | * |
||
| 522 | * @param string $identifier |
||
| 523 | * @return array |
||
| 524 | */ |
||
| 525 | public function getPermissions($identifier) |
||
| 532 | |||
| 533 | /** |
||
| 534 | * Directly output the contents of the file to the output |
||
| 535 | * buffer. Should not take care of header files or flushing |
||
| 536 | * buffer before. Will be taken care of by the Storage. |
||
| 537 | * |
||
| 538 | * @param string $identifier |
||
| 539 | * @return void |
||
| 540 | */ |
||
| 541 | public function dumpFileContents($identifier) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Checks if a given identifier is within a container, e.g. if |
||
| 551 | * a file or folder is within another folder. |
||
| 552 | * This can e.g. be used to check for web-mounts. |
||
| 553 | * |
||
| 554 | * Hint: this also needs to return TRUE if the given identifier |
||
| 555 | * matches the container identifier to allow access to the root |
||
| 556 | * folder of a filemount. |
||
| 557 | * |
||
| 558 | * @param string $folderIdentifier |
||
| 559 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
| 560 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
| 561 | */ |
||
| 562 | 3 | public function isWithin($folderIdentifier, $identifier) |
|
| 576 | |||
| 577 | /** |
||
| 578 | * Returns information about a file. |
||
| 579 | * |
||
| 580 | * @param string $fileIdentifier |
||
| 581 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
| 582 | * If empty all will be extracted |
||
| 583 | * @return array |
||
| 584 | * @throws FileDoesNotExistException |
||
| 585 | */ |
||
| 586 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []) |
||
| 596 | |||
| 597 | /** |
||
| 598 | * Returns information about a file. |
||
| 599 | * |
||
| 600 | * @param string $folderIdentifier |
||
| 601 | 3 | * @return array |
|
| 602 | * @throws FolderDoesNotExistException |
||
| 603 | */ |
||
| 604 | public function getFolderInfoByIdentifier($folderIdentifier) |
||
| 620 | 2 | ||
| 621 | 2 | /** |
|
| 622 | * Returns the identifier of a file inside the folder |
||
| 623 | 3 | * |
|
| 624 | * @param string $fileName |
||
| 625 | * @param string $folderIdentifier |
||
| 626 | * @return string file identifier |
||
| 627 | */ |
||
| 628 | public function getFileInFolder($fileName, $folderIdentifier) |
||
| 632 | |||
| 633 | 3 | /** |
|
| 634 | * Returns a list of files inside the specified path |
||
| 635 | 3 | * |
|
| 636 | 3 | * @param string $folderIdentifier |
|
| 637 | * @param int $start |
||
| 638 | * @param int $numberOfItems |
||
| 639 | * @param bool $recursive |
||
| 640 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 641 | * @param string $sort Property name used to sort the items. |
||
| 642 | * Among them may be: '' (empty, no sorting), name, |
||
| 643 | * fileext, size, tstamp and rw. |
||
| 644 | * If a driver does not support the given property, it |
||
| 645 | * should fall back to "name". |
||
| 646 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 647 | * @return array of FileIdentifiers |
||
| 648 | */ |
||
| 649 | public function getFilesInFolder( |
||
| 673 | |||
| 674 | 3 | /** |
|
| 675 | 3 | * Returns the identifier of a folder inside the folder |
|
| 676 | 3 | * |
|
| 677 | 3 | * @param string $folderName The name of the target folder |
|
| 678 | 2 | * @param string $folderIdentifier |
|
| 679 | 2 | * @return string folder identifier |
|
| 680 | */ |
||
| 681 | 3 | public function getFolderInFolder($folderName, $folderIdentifier) |
|
| 686 | |||
| 687 | /** |
||
| 688 | * Returns a list of folders inside the specified path |
||
| 689 | * |
||
| 690 | * @param string $folderIdentifier |
||
| 691 | * @param int $start |
||
| 692 | * @param int $numberOfItems |
||
| 693 | * @param bool $recursive |
||
| 694 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 695 | * @param string $sort Property name used to sort the items. |
||
| 696 | * Among them may be: '' (empty, no sorting), name, |
||
| 697 | * fileext, size, tstamp and rw. |
||
| 698 | * If a driver does not support the given property, it |
||
| 699 | * should fall back to "name". |
||
| 700 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 701 | * @return array of Folder Identifier |
||
| 702 | * @TODO: Implement pagination with $start and $numberOfItems |
||
| 703 | * @TODO: Implement directory filter callbacks |
||
| 704 | * @TODO: Implement sorting |
||
| 705 | */ |
||
| 706 | public function getFoldersInFolder( |
||
| 731 | |||
| 732 | /** |
||
| 733 | * Returns the number of files inside the specified path |
||
| 734 | * |
||
| 735 | * @param string $folderIdentifier |
||
| 736 | * @param bool $recursive |
||
| 737 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 738 | * @return int Number of files in folder |
||
| 739 | * @TODO: Implement recursive count |
||
| 740 | * @TODO: Implement filename filtering |
||
| 741 | */ |
||
| 742 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []) |
||
| 747 | |||
| 748 | /** |
||
| 749 | * Returns the number of folders inside the specified path |
||
| 750 | * |
||
| 751 | * @param string $folderIdentifier |
||
| 752 | * @param bool $recursive |
||
| 753 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 754 | * @return int Number of folders in folder |
||
| 755 | */ |
||
| 756 | public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []) |
||
| 769 | |||
| 770 | /** |
||
| 771 | * Extracts information about a file from the filesystem. |
||
| 772 | * |
||
| 773 | * @param string $filePath The absolute path to the file |
||
| 774 | * @param string $containerPath The relative path to the file's container |
||
| 775 | * @param array $propertiesToExtract array of properties which should be returned, if empty all will be extracted |
||
| 776 | * @return array |
||
| 777 | */ |
||
| 778 | protected function extractFileInformation($filePath, $containerPath, array $propertiesToExtract = array()) |
||
| 801 | |||
| 802 | /** |
||
| 803 | * Extracts a specific FileInformation from the FileSystems. |
||
| 804 | * |
||
| 805 | * @param string $fileIdentifier |
||
| 806 | * @param string $containerPath |
||
| 807 | * @param string $property |
||
| 808 | * |
||
| 809 | * @return bool|int|string |
||
| 810 | * @throws \InvalidArgumentException |
||
| 811 | */ |
||
| 812 | public function getSpecificFileInformation($fileIdentifier, $containerPath, $property) |
||
| 842 | } |
||
| 843 |