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 |
||
| 20 | abstract class FlysystemDriver extends AbstractHierarchicalFilesystemDriver |
||
| 21 | { |
||
| 22 | /** |
||
| 23 | * @var FilesystemInterface |
||
| 24 | */ |
||
| 25 | protected $filesystem; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var AdapterInterface |
||
| 29 | */ |
||
| 30 | protected $adapter; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $entryPath; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * FlysystemDriver constructor. |
||
| 39 | * @param array $configuration |
||
| 40 | */ |
||
| 41 | 36 | public function __construct(array $configuration = []) |
|
| 50 | |||
| 51 | /** |
||
| 52 | * Processes the configuration for this driver. |
||
| 53 | * @return void |
||
| 54 | */ |
||
| 55 | public function processConfiguration() |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Merges the capabilities merged by the user at the storage |
||
| 62 | * configuration into the actual capabilities of the driver |
||
| 63 | * and returns the result. |
||
| 64 | * |
||
| 65 | * @param int $capabilities |
||
| 66 | * @return int |
||
| 67 | */ |
||
| 68 | public function mergeConfigurationCapabilities($capabilities) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Returns the identifier of the root level folder of the storage. |
||
| 75 | * |
||
| 76 | * @return string |
||
| 77 | */ |
||
| 78 | public function getRootLevelFolder() |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Returns the identifier of the default folder new files should be put into. |
||
| 85 | * |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | 3 | public function getDefaultFolder() |
|
| 97 | |||
| 98 | /** |
||
| 99 | * Checks if a folder exists. |
||
| 100 | * |
||
| 101 | * @param string $folderIdentifier |
||
| 102 | * @return bool |
||
| 103 | */ |
||
| 104 | 6 | public function folderExists($folderIdentifier) |
|
| 112 | |||
| 113 | /** |
||
| 114 | * Creates a folder, within a parent folder. |
||
| 115 | * If no parent folder is given, a root level folder will be created |
||
| 116 | * |
||
| 117 | * @param string $newFolderName |
||
| 118 | * @param string $parentFolderIdentifier |
||
| 119 | * @param bool $recursive |
||
| 120 | * @return string the Identifier of the new folder |
||
| 121 | */ |
||
| 122 | 9 | public function createFolder($newFolderName, $parentFolderIdentifier = '', $recursive = false) |
|
| 138 | |||
| 139 | /** |
||
| 140 | * Returns the public URL to a file. |
||
| 141 | * Either fully qualified URL or relative to PATH_site (rawurlencoded). |
||
| 142 | * |
||
| 143 | * @param string $identifier |
||
| 144 | * @return string |
||
| 145 | */ |
||
| 146 | public function getPublicUrl($identifier) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * Renames a folder in this storage. |
||
| 156 | * |
||
| 157 | * @param string $folderIdentifier |
||
| 158 | * @param string $newName |
||
| 159 | * @return array A map of old to new file identifiers of all affected resources |
||
| 160 | */ |
||
| 161 | 3 | public function renameFolder($folderIdentifier, $newName) |
|
| 171 | |||
| 172 | /** |
||
| 173 | * Removes a folder in filesystem. |
||
| 174 | * |
||
| 175 | * @param string $folderIdentifier |
||
| 176 | * @param bool $deleteRecursively |
||
| 177 | * @return bool |
||
| 178 | */ |
||
| 179 | public function deleteFolder($folderIdentifier, $deleteRecursively = false) |
||
| 183 | |||
| 184 | /** |
||
| 185 | * Checks if a file exists. |
||
| 186 | * |
||
| 187 | * @param string $fileIdentifier |
||
| 188 | * @return bool |
||
| 189 | */ |
||
| 190 | 6 | public function fileExists($fileIdentifier) |
|
| 194 | |||
| 195 | /** |
||
| 196 | * Checks if a folder contains files and (if supported) other folders. |
||
| 197 | * |
||
| 198 | * @param string $folderIdentifier |
||
| 199 | * @return bool TRUE if there are no files and folders within $folder |
||
| 200 | */ |
||
| 201 | 3 | public function isFolderEmpty($folderIdentifier) |
|
| 205 | |||
| 206 | /** |
||
| 207 | * Adds a file from the local server hard disk to a given path in TYPO3s |
||
| 208 | * virtual file system. This assumes that the local file exists, so no |
||
| 209 | * further check is done here! After a successful the original file must |
||
| 210 | * not exist anymore. |
||
| 211 | * |
||
| 212 | * @param string $localFilePath (within PATH_site) |
||
| 213 | * @param string $targetFolderIdentifier |
||
| 214 | * @param string $newFileName optional, if not given original name is used |
||
| 215 | * @param bool $removeOriginal if set the original file will be removed |
||
| 216 | * after successful operation |
||
| 217 | * @return string the identifier of the new file |
||
| 218 | */ |
||
| 219 | 3 | public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true) |
|
| 245 | |||
| 246 | /** |
||
| 247 | * Creates a new (empty) file and returns the identifier. |
||
| 248 | * |
||
| 249 | * @param string $fileName |
||
| 250 | * @param string $parentFolderIdentifier |
||
| 251 | * @return string |
||
| 252 | */ |
||
| 253 | public function createFile($fileName, $parentFolderIdentifier) |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Copies a file *within* the current storage. |
||
| 264 | * Note that this is only about an inner storage copy action, |
||
| 265 | * where a file is just copied to another folder in the same storage. |
||
| 266 | * |
||
| 267 | * @param string $fileIdentifier |
||
| 268 | * @param string $targetFolderIdentifier |
||
| 269 | * @param string $fileName |
||
| 270 | * @return string the Identifier of the new file |
||
| 271 | */ |
||
| 272 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
| 281 | |||
| 282 | /** |
||
| 283 | * Renames a file in this storage. |
||
| 284 | * |
||
| 285 | * @param string $fileIdentifier |
||
| 286 | * @param string $newName The target path (including the file name!) |
||
| 287 | * @return string The identifier of the file after renaming |
||
| 288 | */ |
||
| 289 | public function renameFile($fileIdentifier, $newName) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Replaces a file with file in local file system. |
||
| 300 | * |
||
| 301 | * @param string $fileIdentifier |
||
| 302 | * @param string $localFilePath |
||
| 303 | * @return bool TRUE if the operation succeeded |
||
| 304 | */ |
||
| 305 | public function replaceFile($fileIdentifier, $localFilePath) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Removes a file from the filesystem. This does not check if the file is |
||
| 316 | * still used or if it is a bad idea to delete it for some other reason |
||
| 317 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
| 318 | * |
||
| 319 | * @param string $fileIdentifier |
||
| 320 | * @return bool TRUE if deleting the file succeeded |
||
| 321 | */ |
||
| 322 | public function deleteFile($fileIdentifier) |
||
| 326 | |||
| 327 | /** |
||
| 328 | * Creates a hash for a file. |
||
| 329 | * |
||
| 330 | * @param string $fileIdentifier |
||
| 331 | * @param string $hashAlgorithm The hash algorithm to use |
||
| 332 | * @return string |
||
| 333 | */ |
||
| 334 | public function hash($fileIdentifier, $hashAlgorithm) |
||
| 338 | |||
| 339 | /** |
||
| 340 | * Moves a file *within* the current storage. |
||
| 341 | * Note that this is only about an inner-storage move action, |
||
| 342 | * where a file is just moved to another folder in the same storage. |
||
| 343 | * |
||
| 344 | * @param string $fileIdentifier |
||
| 345 | * @param string $targetFolderIdentifier |
||
| 346 | * @param string $newFileName |
||
| 347 | * @return string |
||
| 348 | */ |
||
| 349 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Folder equivalent to moveFileWithinStorage(). |
||
| 356 | * |
||
| 357 | * @param string $sourceFolderIdentifier |
||
| 358 | * @param string $targetFolderIdentifier |
||
| 359 | * @param string $newFolderName |
||
| 360 | * @return array All files which are affected, map of old => new file identifiers |
||
| 361 | */ |
||
| 362 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 366 | |||
| 367 | /** |
||
| 368 | * Folder equivalent to copyFileWithinStorage(). |
||
| 369 | * |
||
| 370 | * @param string $sourceFolderIdentifier |
||
| 371 | * @param string $targetFolderIdentifier |
||
| 372 | * @param string $newFolderName |
||
| 373 | * @return bool |
||
| 374 | */ |
||
| 375 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
| 379 | |||
| 380 | /** |
||
| 381 | * Returns the contents of a file. Beware that this requires to load the |
||
| 382 | * complete file into memory and also may require fetching the file from an |
||
| 383 | * external location. So this might be an expensive operation (both in terms |
||
| 384 | * of processing resources and money) for large files. |
||
| 385 | * |
||
| 386 | * @param string $fileIdentifier |
||
| 387 | * @return string The file contents |
||
| 388 | */ |
||
| 389 | 3 | public function getFileContents($fileIdentifier) |
|
| 393 | |||
| 394 | /** |
||
| 395 | * Sets the contents of a file to the specified value. |
||
| 396 | * |
||
| 397 | * @param string $fileIdentifier |
||
| 398 | * @param string $contents |
||
| 399 | * @return int The number of bytes written to the file |
||
| 400 | */ |
||
| 401 | 3 | public function setFileContents($fileIdentifier, $contents) |
|
| 407 | |||
| 408 | /** |
||
| 409 | * Checks if a file inside a folder exists |
||
| 410 | * |
||
| 411 | * @param string $fileName |
||
| 412 | * @param string $folderIdentifier |
||
| 413 | * @return bool |
||
| 414 | */ |
||
| 415 | 3 | public function fileExistsInFolder($fileName, $folderIdentifier) |
|
| 421 | |||
| 422 | /** |
||
| 423 | * Checks if a folder inside a folder exists. |
||
| 424 | * |
||
| 425 | * @param string $folderName |
||
| 426 | * @param string $folderIdentifier |
||
| 427 | * @return bool |
||
| 428 | */ |
||
| 429 | public function folderExistsInFolder($folderName, $folderIdentifier) |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Returns a path to a local copy of a file for processing it. When changing the |
||
| 436 | * file, you have to take care of replacing the current version yourself! |
||
| 437 | * |
||
| 438 | * @param string $fileIdentifier |
||
| 439 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
| 440 | * operations. This might speed up things, e.g. by using |
||
| 441 | * a cached local version. Never modify the file if you |
||
| 442 | * have set this flag! |
||
| 443 | * @return string The path to the file on the local disk |
||
| 444 | */ |
||
| 445 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
| 453 | |||
| 454 | /** |
||
| 455 | * Returns the permissions of a file/folder as an array |
||
| 456 | * (keys r, w) of boolean flags |
||
| 457 | * |
||
| 458 | * @param string $identifier |
||
| 459 | * @return array |
||
| 460 | */ |
||
| 461 | public function getPermissions($identifier) |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Directly output the contents of the file to the output |
||
| 471 | * buffer. Should not take care of header files or flushing |
||
| 472 | * buffer before. Will be taken care of by the Storage. |
||
| 473 | * |
||
| 474 | * @param string $identifier |
||
| 475 | * @return void |
||
| 476 | */ |
||
| 477 | public function dumpFileContents($identifier) |
||
| 484 | |||
| 485 | /** |
||
| 486 | * Checks if a given identifier is within a container, e.g. if |
||
| 487 | * a file or folder is within another folder. |
||
| 488 | * This can e.g. be used to check for web-mounts. |
||
| 489 | * |
||
| 490 | * Hint: this also needs to return TRUE if the given identifier |
||
| 491 | * matches the container identifier to allow access to the root |
||
| 492 | * folder of a filemount. |
||
| 493 | * |
||
| 494 | * @param string $folderIdentifier |
||
| 495 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
| 496 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
| 497 | */ |
||
| 498 | public function isWithin($folderIdentifier, $identifier) |
||
| 512 | |||
| 513 | /** |
||
| 514 | * Returns information about a file. |
||
| 515 | * |
||
| 516 | * @param string $fileIdentifier |
||
| 517 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
| 518 | * If empty all will be extracted |
||
| 519 | * @return array |
||
| 520 | */ |
||
| 521 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []) |
||
| 531 | |||
| 532 | /** |
||
| 533 | * Returns information about a file. |
||
| 534 | * |
||
| 535 | * @param string $folderIdentifier |
||
| 536 | * @return array |
||
| 537 | */ |
||
| 538 | public function getFolderInfoByIdentifier($folderIdentifier) |
||
| 548 | |||
| 549 | /** |
||
| 550 | * Returns the identifier of a file inside the folder |
||
| 551 | * |
||
| 552 | * @param string $fileName |
||
| 553 | * @param string $folderIdentifier |
||
| 554 | * @return string file identifier |
||
| 555 | */ |
||
| 556 | public function getFileInFolder($fileName, $folderIdentifier) |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Returns a list of files inside the specified path |
||
| 563 | * |
||
| 564 | * @param string $folderIdentifier |
||
| 565 | * @param int $start |
||
| 566 | * @param int $numberOfItems |
||
| 567 | * @param bool $recursive |
||
| 568 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 569 | * @param string $sort Property name used to sort the items. |
||
| 570 | * Among them may be: '' (empty, no sorting), name, |
||
| 571 | * fileext, size, tstamp and rw. |
||
| 572 | * If a driver does not support the given property, it |
||
| 573 | * should fall back to "name". |
||
| 574 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 575 | * @return array of FileIdentifiers |
||
| 576 | */ |
||
| 577 | 3 | public function getFilesInFolder( |
|
| 601 | |||
| 602 | /** |
||
| 603 | * Returns the identifier of a folder inside the folder |
||
| 604 | * |
||
| 605 | * @param string $folderName The name of the target folder |
||
| 606 | * @param string $folderIdentifier |
||
| 607 | * @return string folder identifier |
||
| 608 | */ |
||
| 609 | public function getFolderInFolder($folderName, $folderIdentifier) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Returns a list of folders inside the specified path |
||
| 617 | * |
||
| 618 | * @param string $folderIdentifier |
||
| 619 | * @param int $start |
||
| 620 | * @param int $numberOfItems |
||
| 621 | * @param bool $recursive |
||
| 622 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 623 | * @param string $sort Property name used to sort the items. |
||
| 624 | * Among them may be: '' (empty, no sorting), name, |
||
| 625 | * fileext, size, tstamp and rw. |
||
| 626 | * If a driver does not support the given property, it |
||
| 627 | * should fall back to "name". |
||
| 628 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
| 629 | * @return array of Folder Identifier |
||
| 630 | * @TODO: Implement pagination with $start and $numberOfItems |
||
| 631 | * @TODO: Implement directory filter callbacks |
||
| 632 | * @TODO: Implement sorting |
||
| 633 | */ |
||
| 634 | 3 | public function getFoldersInFolder( |
|
| 659 | |||
| 660 | /** |
||
| 661 | * Returns the number of files inside the specified path |
||
| 662 | * |
||
| 663 | * @param string $folderIdentifier |
||
| 664 | * @param bool $recursive |
||
| 665 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
| 666 | * @return int Number of files in folder |
||
| 667 | * @TODO: Implement recursive count |
||
| 668 | * @TODO: Implement filename filtering |
||
| 669 | */ |
||
| 670 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []) |
||
| 675 | |||
| 676 | /** |
||
| 677 | * Returns the number of folders inside the specified path |
||
| 678 | * |
||
| 679 | * @param string $folderIdentifier |
||
| 680 | * @param bool $recursive |
||
| 681 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
| 682 | * @return int Number of folders in folder |
||
| 683 | */ |
||
| 684 | 3 | public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []) |
|
| 697 | |||
| 698 | /** |
||
| 699 | * Extracts information about a file from the filesystem. |
||
| 700 | * |
||
| 701 | * @param string $filePath The absolute path to the file |
||
| 702 | * @param string $containerPath The relative path to the file's container |
||
| 703 | * @param array $propertiesToExtract array of properties which should be returned, if empty all will be extracted |
||
| 704 | * @return array |
||
| 705 | */ |
||
| 706 | protected function extractFileInformation($filePath, $containerPath, array $propertiesToExtract = array()) |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Extracts a specific FileInformation from the FileSystems. |
||
| 732 | * |
||
| 733 | * @param string $fileIdentifier |
||
| 734 | * @param string $containerPath |
||
| 735 | * @param string $property |
||
| 736 | * |
||
| 737 | * @return bool|int|string |
||
| 738 | * @throws \InvalidArgumentException |
||
| 739 | */ |
||
| 740 | public function getSpecificFileInformation($fileIdentifier, $containerPath, $property) |
||
| 770 | } |
||
| 771 |