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 |
||
| 22 | abstract class FlysystemDriver extends AbstractHierarchicalFilesystemDriver |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var FilesystemInterface |
||
| 26 | */ |
||
| 27 | protected $filesystem; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var AdapterInterface |
||
| 31 | */ |
||
| 32 | protected $adapter; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | protected $entryPath; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * FlysystemDriver constructor. |
||
| 41 | * @param array $configuration |
||
| 42 | */ |
||
| 43 | 51 | public function __construct(array $configuration = []) |
|
| 52 | |||
| 53 | /** |
||
| 54 | * Processes the configuration for this driver. |
||
| 55 | * @return void |
||
| 56 | */ |
||
| 57 | public function processConfiguration() |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Merges the capabilities merged by the user at the storage |
||
| 64 | * configuration into the actual capabilities of the driver |
||
| 65 | * and returns the result. |
||
| 66 | * |
||
| 67 | * @param int $capabilities |
||
| 68 | * @return int |
||
| 69 | */ |
||
| 70 | public function mergeConfigurationCapabilities($capabilities) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Returns the identifier of the root level folder of the storage. |
||
| 77 | * |
||
| 78 | * @return string |
||
| 79 | */ |
||
| 80 | public function getRootLevelFolder() |
||
| 84 | |||
| 85 | /** |
||
| 86 | * Returns the identifier of the default folder new files should be put into. |
||
| 87 | * |
||
| 88 | * @return string |
||
| 89 | */ |
||
| 90 | 3 | public function getDefaultFolder() |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Checks if a folder exists. |
||
| 102 | * |
||
| 103 | * @param string $folderIdentifier |
||
| 104 | * @return bool |
||
| 105 | */ |
||
| 106 | 6 | public function folderExists($folderIdentifier) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * Creates a folder, within a parent folder. |
||
| 117 | * If no parent folder is given, a root level folder will be created |
||
| 118 | * |
||
| 119 | * @param string $newFolderName |
||
| 120 | * @param string $parentFolderIdentifier |
||
| 121 | * @param bool $recursive |
||
| 122 | * @return string the Identifier of the new folder |
||
| 123 | */ |
||
| 124 | 9 | public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false) |
|
| 135 | |||
| 136 | /** |
||
| 137 | * Returns the public URL to a file. |
||
| 138 | * Either fully qualified URL or relative to PATH_site (rawurlencoded). |
||
| 139 | * |
||
| 140 | * @param string $identifier |
||
| 141 | * @return string |
||
| 142 | */ |
||
| 143 | public function getPublicUrl($identifier) |
||
| 147 | |||
| 148 | /** |
||
| 149 | * Renames a folder in this storage. |
||
| 150 | * |
||
| 151 | * @param string $folderIdentifier |
||
| 152 | * @param string $newName |
||
| 153 | * @return array A map of old to new file identifiers of all affected resources |
||
| 154 | */ |
||
| 155 | 3 | public function renameFolder($folderIdentifier, $newName) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Removes a folder in filesystem. |
||
| 168 | * |
||
| 169 | * @param string $folderIdentifier |
||
| 170 | * @param bool $deleteRecursively |
||
| 171 | * @return bool |
||
| 172 | * @throws FileOperationErrorException |
||
| 173 | */ |
||
| 174 | public function deleteFolder($folderIdentifier, $deleteRecursively = false) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Checks if a file exists. |
||
| 189 | * |
||
| 190 | * @param string $fileIdentifier |
||
| 191 | * @return bool |
||
| 192 | */ |
||
| 193 | 12 | public function fileExists($fileIdentifier) |
|
| 200 | |||
| 201 | /** |
||
| 202 | * Checks if a folder contains files and (if supported) other folders. |
||
| 203 | * |
||
| 204 | * @param string $folderIdentifier |
||
| 205 | * @return bool TRUE if there are no files and folders within $folder |
||
| 206 | */ |
||
| 207 | 3 | public function isFolderEmpty($folderIdentifier) |
|
| 211 | |||
| 212 | /** |
||
| 213 | * Adds a file from the local server hard disk to a given path in TYPO3s |
||
| 214 | * virtual file system. This assumes that the local file exists, so no |
||
| 215 | * further check is done here! After a successful the original file must |
||
| 216 | * not exist anymore. |
||
| 217 | * |
||
| 218 | * @param string $localFilePath (within PATH_site) |
||
| 219 | * @param string $targetFolderIdentifier |
||
| 220 | * @param string $newFileName optional, if not given original name is used |
||
| 221 | * @param bool $removeOriginal if set the original file will be removed |
||
| 222 | * after successful operation |
||
| 223 | * @return string the identifier of the new file |
||
| 224 | */ |
||
| 225 | 3 | public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true) |
|
| 251 | |||
| 252 | /** |
||
| 253 | * Creates a new (empty) file and returns the identifier. |
||
| 254 | * |
||
| 255 | * @param string $fileName |
||
| 256 | * @param string $parentFolderIdentifier |
||
| 257 | * @return string |
||
| 258 | * @throws InvalidFileNameException |
||
| 259 | */ |
||
| 260 | 5 | public function createFile($fileName, $parentFolderIdentifier) |
|
| 283 | |||
| 284 | /** |
||
| 285 | * Copies a file *within* the current storage. |
||
| 286 | * Note that this is only about an inner storage copy action, |
||
| 287 | * where a file is just copied to another folder in the same storage. |
||
| 288 | * |
||
| 289 | * @param string $fileIdentifier |
||
| 290 | * @param string $targetFolderIdentifier |
||
| 291 | * @param string $fileName |
||
| 292 | * @return string the Identifier of the new file |
||
| 293 | */ |
||
| 294 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Renames a file in this storage. |
||
| 306 | * |
||
| 307 | * @param string $fileIdentifier |
||
| 308 | * @param string $newName The target path (including the file name!) |
||
| 309 | * @return string The identifier of the file after renaming |
||
| 310 | */ |
||
| 311 | public function renameFile($fileIdentifier, $newName) |
||
| 319 | |||
| 320 | /** |
||
| 321 | * Replaces a file with file in local file system. |
||
| 322 | * |
||
| 323 | * @param string $fileIdentifier |
||
| 324 | * @param string $localFilePath |
||
| 325 | * @return bool TRUE if the operation succeeded |
||
| 326 | */ |
||
| 327 | public function replaceFile($fileIdentifier, $localFilePath) |
||
| 335 | |||
| 336 | /** |
||
| 337 | * Removes a file from the filesystem. This does not check if the file is |
||
| 338 | * still used or if it is a bad idea to delete it for some other reason |
||
| 339 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
| 340 | * |
||
| 341 | * @param string $fileIdentifier |
||
| 342 | * @return bool TRUE if deleting the file succeeded |
||
| 343 | */ |
||
| 344 | 3 | public function deleteFile($fileIdentifier) |
|
| 348 | |||
| 349 | /** |
||
| 350 | * Creates a hash for a file. |
||
| 351 | * |
||
| 352 | * @param string $fileIdentifier |
||
| 353 | * @param string $hashAlgorithm The hash algorithm to use |
||
| 354 | * @return string |
||
| 355 | */ |
||
| 356 | public function hash($fileIdentifier, $hashAlgorithm) |
||
| 360 | |||
| 361 | /** |
||
| 362 | * Moves a file *within* the current storage. |
||
| 363 | * Note that this is only about an inner-storage move action, |
||
| 364 | * where a file is just moved to another folder in the same storage. |
||
| 365 | * |
||
| 366 | * @param string $fileIdentifier |
||
| 367 | * @param string $targetFolderIdentifier |
||
| 368 | * @param string $newFileName |
||
| 369 | * @return string |
||
| 370 | */ |
||
| 371 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
||
| 375 | |||
| 376 | /** |
||
| 377 | * Folder equivalent to moveFileWithinStorage(). |
||
| 378 | * |
||
| 379 | * @param string $sourceFolderIdentifier |
||
| 380 | * @param string $targetFolderIdentifier |
||
| 381 | * @param string $newFolderName |
||
| 382 | * @return array All files which are affected, map of old => new file identifiers |
||
| 383 | */ |
||
| 384 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 388 | |||
| 389 | /** |
||
| 390 | * Folder equivalent to copyFileWithinStorage(). |
||
| 391 | * |
||
| 392 | * @param string $sourceFolderIdentifier |
||
| 393 | * @param string $targetFolderIdentifier |
||
| 394 | * @param string $newFolderName |
||
| 395 | * @return bool |
||
| 396 | */ |
||
| 397 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 401 | |||
| 402 | /** |
||
| 403 | * Returns the contents of a file. Beware that this requires to load the |
||
| 404 | * complete file into memory and also may require fetching the file from an |
||
| 405 | * external location. So this might be an expensive operation (both in terms |
||
| 406 | * of processing resources and money) for large files. |
||
| 407 | * |
||
| 408 | * @param string $fileIdentifier |
||
| 409 | * @return string The file contents |
||
| 410 | */ |
||
| 411 | 3 | public function getFileContents($fileIdentifier) |
|
| 415 | |||
| 416 | /** |
||
| 417 | * Sets the contents of a file to the specified value. |
||
| 418 | * |
||
| 419 | * @param string $fileIdentifier |
||
| 420 | * @param string $contents |
||
| 421 | * @return int The number of bytes written to the file |
||
| 422 | */ |
||
| 423 | 3 | public function setFileContents($fileIdentifier, $contents) |
|
| 429 | |||
| 430 | /** |
||
| 431 | * Checks if a file inside a folder exists |
||
| 432 | * |
||
| 433 | * @param string $fileName |
||
| 434 | * @param string $folderIdentifier |
||
| 435 | * @return bool |
||
| 436 | */ |
||
| 437 | 3 | public function fileExistsInFolder($fileName, $folderIdentifier) |
|
| 443 | |||
| 444 | /** |
||
| 445 | * Checks if a folder inside a folder exists. |
||
| 446 | * |
||
| 447 | * @param string $folderName |
||
| 448 | * @param string $folderIdentifier |
||
| 449 | * @return bool |
||
| 450 | */ |
||
| 451 | 3 | public function folderExistsInFolder($folderName, $folderIdentifier) |
|
| 457 | |||
| 458 | /** |
||
| 459 | * Returns a path to a local copy of a file for processing it. When changing the |
||
| 460 | * file, you have to take care of replacing the current version yourself! |
||
| 461 | * |
||
| 462 | * @param string $fileIdentifier |
||
| 463 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
| 464 | * operations. This might speed up things, e.g. by using |
||
| 465 | * a cached local version. Never modify the file if you |
||
| 466 | * have set this flag! |
||
| 467 | * @return string The path to the file on the local disk |
||
| 468 | */ |
||
| 469 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
| 477 | |||
| 478 | /** |
||
| 479 | * Returns the permissions of a file/folder as an array |
||
| 480 | * (keys r, w) of boolean flags |
||
| 481 | * |
||
| 482 | * @param string $identifier |
||
| 483 | * @return array |
||
| 484 | */ |
||
| 485 | public function getPermissions($identifier) |
||
| 492 | |||
| 493 | /** |
||
| 494 | * Directly output the contents of the file to the output |
||
| 495 | * buffer. Should not take care of header files or flushing |
||
| 496 | * buffer before. Will be taken care of by the Storage. |
||
| 497 | * |
||
| 498 | * @param string $identifier |
||
| 499 | * @return void |
||
| 500 | */ |
||
| 501 | public function dumpFileContents($identifier) |
||
| 508 | |||
| 509 | /** |
||
| 510 | * Checks if a given identifier is within a container, e.g. if |
||
| 511 | * a file or folder is within another folder. |
||
| 512 | * This can e.g. be used to check for web-mounts. |
||
| 513 | * |
||
| 514 | * Hint: this also needs to return TRUE if the given identifier |
||
| 515 | * matches the container identifier to allow access to the root |
||
| 516 | * folder of a filemount. |
||
| 517 | * |
||
| 518 | * @param string $folderIdentifier |
||
| 519 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
| 520 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
| 521 | */ |
||
| 522 | public function isWithin($folderIdentifier, $identifier) |
||
| 536 | |||
| 537 | /** |
||
| 538 | * Returns information about a file. |
||
| 539 | * |
||
| 540 | * @param string $fileIdentifier |
||
| 541 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
| 542 | * If empty all will be extracted |
||
| 543 | * @return array |
||
| 544 | */ |
||
| 545 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []) |
||
| 555 | |||
| 556 | /** |
||
| 557 | * Returns information about a file. |
||
| 558 | * |
||
| 559 | * @param string $folderIdentifier |
||
| 560 | * @return array |
||
| 561 | */ |
||
| 562 | 3 | public function getFolderInfoByIdentifier($folderIdentifier) |
|
| 572 | |||
| 573 | /** |
||
| 574 | * Returns the identifier of a file inside the folder |
||
| 575 | * |
||
| 576 | * @param string $fileName |
||
| 577 | * @param string $folderIdentifier |
||
| 578 | * @return string file identifier |
||
| 579 | */ |
||
| 580 | public function getFileInFolder($fileName, $folderIdentifier) |
||
| 584 | |||
| 585 | /** |
||
| 586 | * Returns a list of files inside the specified path |
||
| 587 | * |
||
| 588 | * @param string $folderIdentifier |
||
| 589 | * @param int $start |
||
| 590 | * @param int $numberOfItems |
||
| 591 | * @param bool $recursive |
||
| 592 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 593 | * @param string $sort Property name used to sort the items. |
||
| 594 | * Among them may be: '' (empty, no sorting), name, |
||
| 595 | * fileext, size, tstamp and rw. |
||
| 596 | * If a driver does not support the given property, it |
||
| 597 | * should fall back to "name". |
||
| 598 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 599 | * @return array of FileIdentifiers |
||
| 600 | */ |
||
| 601 | 3 | public function getFilesInFolder( |
|
| 625 | |||
| 626 | /** |
||
| 627 | * Returns the identifier of a folder inside the folder |
||
| 628 | * |
||
| 629 | * @param string $folderName The name of the target folder |
||
| 630 | * @param string $folderIdentifier |
||
| 631 | * @return string folder identifier |
||
| 632 | */ |
||
| 633 | 3 | public function getFolderInFolder($folderName, $folderIdentifier) |
|
| 638 | |||
| 639 | /** |
||
| 640 | * Returns a list of folders inside the specified path |
||
| 641 | * |
||
| 642 | * @param string $folderIdentifier |
||
| 643 | * @param int $start |
||
| 644 | * @param int $numberOfItems |
||
| 645 | * @param bool $recursive |
||
| 646 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 647 | * @param string $sort Property name used to sort the items. |
||
| 648 | * Among them may be: '' (empty, no sorting), name, |
||
| 649 | * fileext, size, tstamp and rw. |
||
| 650 | * If a driver does not support the given property, it |
||
| 651 | * should fall back to "name". |
||
| 652 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 653 | * @return array of Folder Identifier |
||
| 654 | * @TODO: Implement pagination with $start and $numberOfItems |
||
| 655 | * @TODO: Implement directory filter callbacks |
||
| 656 | * @TODO: Implement sorting |
||
| 657 | */ |
||
| 658 | 3 | public function getFoldersInFolder( |
|
| 683 | |||
| 684 | /** |
||
| 685 | * Returns the number of files inside the specified path |
||
| 686 | * |
||
| 687 | * @param string $folderIdentifier |
||
| 688 | * @param bool $recursive |
||
| 689 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 690 | * @return int Number of files in folder |
||
| 691 | * @TODO: Implement recursive count |
||
| 692 | * @TODO: Implement filename filtering |
||
| 693 | */ |
||
| 694 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []) |
||
| 699 | |||
| 700 | /** |
||
| 701 | * Returns the number of folders inside the specified path |
||
| 702 | * |
||
| 703 | * @param string $folderIdentifier |
||
| 704 | * @param bool $recursive |
||
| 705 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 706 | * @return int Number of folders in folder |
||
| 707 | */ |
||
| 708 | 3 | public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []) |
|
| 721 | |||
| 722 | /** |
||
| 723 | * Extracts information about a file from the filesystem. |
||
| 724 | * |
||
| 725 | * @param string $filePath The absolute path to the file |
||
| 726 | * @param string $containerPath The relative path to the file's container |
||
| 727 | * @param array $propertiesToExtract array of properties which should be returned, if empty all will be extracted |
||
| 728 | * @return array |
||
| 729 | */ |
||
| 730 | protected function extractFileInformation($filePath, $containerPath, array $propertiesToExtract = array()) |
||
| 753 | |||
| 754 | /** |
||
| 755 | * Extracts a specific FileInformation from the FileSystems. |
||
| 756 | * |
||
| 757 | * @param string $fileIdentifier |
||
| 758 | * @param string $containerPath |
||
| 759 | * @param string $property |
||
| 760 | * |
||
| 761 | * @return bool|int|string |
||
| 762 | * @throws \InvalidArgumentException |
||
| 763 | */ |
||
| 764 | public function getSpecificFileInformation($fileIdentifier, $containerPath, $property) |
||
| 794 | } |
||
| 795 |