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) |
|
197 | |||
198 | /** |
||
199 | * Checks if a folder contains files and (if supported) other folders. |
||
200 | * |
||
201 | * @param string $folderIdentifier |
||
202 | * @return bool TRUE if there are no files and folders within $folder |
||
203 | */ |
||
204 | 3 | public function isFolderEmpty($folderIdentifier) |
|
208 | |||
209 | /** |
||
210 | * Adds a file from the local server hard disk to a given path in TYPO3s |
||
211 | * virtual file system. This assumes that the local file exists, so no |
||
212 | * further check is done here! After a successful the original file must |
||
213 | * not exist anymore. |
||
214 | * |
||
215 | * @param string $localFilePath (within PATH_site) |
||
216 | * @param string $targetFolderIdentifier |
||
217 | * @param string $newFileName optional, if not given original name is used |
||
218 | * @param bool $removeOriginal if set the original file will be removed |
||
219 | * after successful operation |
||
220 | * @return string the identifier of the new file |
||
221 | */ |
||
222 | 3 | public function addFile($localFilePath, $targetFolderIdentifier, $newFileName = '', $removeOriginal = true) |
|
248 | |||
249 | /** |
||
250 | * Creates a new (empty) file and returns the identifier. |
||
251 | * |
||
252 | * @param string $fileName |
||
253 | * @param string $parentFolderIdentifier |
||
254 | * @return string |
||
255 | */ |
||
256 | public function createFile($fileName, $parentFolderIdentifier) |
||
264 | |||
265 | /** |
||
266 | * Copies a file *within* the current storage. |
||
267 | * Note that this is only about an inner storage copy action, |
||
268 | * where a file is just copied to another folder in the same storage. |
||
269 | * |
||
270 | * @param string $fileIdentifier |
||
271 | * @param string $targetFolderIdentifier |
||
272 | * @param string $fileName |
||
273 | * @return string the Identifier of the new file |
||
274 | */ |
||
275 | public function copyFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $fileName) |
||
284 | |||
285 | /** |
||
286 | * Renames a file in this storage. |
||
287 | * |
||
288 | * @param string $fileIdentifier |
||
289 | * @param string $newName The target path (including the file name!) |
||
290 | * @return string The identifier of the file after renaming |
||
291 | */ |
||
292 | public function renameFile($fileIdentifier, $newName) |
||
300 | |||
301 | /** |
||
302 | * Replaces a file with file in local file system. |
||
303 | * |
||
304 | * @param string $fileIdentifier |
||
305 | * @param string $localFilePath |
||
306 | * @return bool TRUE if the operation succeeded |
||
307 | */ |
||
308 | public function replaceFile($fileIdentifier, $localFilePath) |
||
316 | |||
317 | /** |
||
318 | * Removes a file from the filesystem. This does not check if the file is |
||
319 | * still used or if it is a bad idea to delete it for some other reason |
||
320 | * this has to be taken care of in the upper layers (e.g. the Storage)! |
||
321 | * |
||
322 | * @param string $fileIdentifier |
||
323 | * @return bool TRUE if deleting the file succeeded |
||
324 | */ |
||
325 | public function deleteFile($fileIdentifier) |
||
329 | |||
330 | /** |
||
331 | * Creates a hash for a file. |
||
332 | * |
||
333 | * @param string $fileIdentifier |
||
334 | * @param string $hashAlgorithm The hash algorithm to use |
||
335 | * @return string |
||
336 | */ |
||
337 | public function hash($fileIdentifier, $hashAlgorithm) |
||
341 | |||
342 | /** |
||
343 | * Moves a file *within* the current storage. |
||
344 | * Note that this is only about an inner-storage move action, |
||
345 | * where a file is just moved to another folder in the same storage. |
||
346 | * |
||
347 | * @param string $fileIdentifier |
||
348 | * @param string $targetFolderIdentifier |
||
349 | * @param string $newFileName |
||
350 | * @return string |
||
351 | */ |
||
352 | public function moveFileWithinStorage($fileIdentifier, $targetFolderIdentifier, $newFileName) |
||
356 | |||
357 | /** |
||
358 | * Folder equivalent to moveFileWithinStorage(). |
||
359 | * |
||
360 | * @param string $sourceFolderIdentifier |
||
361 | * @param string $targetFolderIdentifier |
||
362 | * @param string $newFolderName |
||
363 | * @return array All files which are affected, map of old => new file identifiers |
||
364 | */ |
||
365 | public function moveFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
369 | |||
370 | /** |
||
371 | * Folder equivalent to copyFileWithinStorage(). |
||
372 | * |
||
373 | * @param string $sourceFolderIdentifier |
||
374 | * @param string $targetFolderIdentifier |
||
375 | * @param string $newFolderName |
||
376 | * @return bool |
||
377 | */ |
||
378 | public function copyFolderWithinStorage($sourceFolderIdentifier, $targetFolderIdentifier, $newFolderName) |
||
382 | |||
383 | /** |
||
384 | * Returns the contents of a file. Beware that this requires to load the |
||
385 | * complete file into memory and also may require fetching the file from an |
||
386 | * external location. So this might be an expensive operation (both in terms |
||
387 | * of processing resources and money) for large files. |
||
388 | * |
||
389 | * @param string $fileIdentifier |
||
390 | * @return string The file contents |
||
391 | */ |
||
392 | 3 | public function getFileContents($fileIdentifier) |
|
396 | |||
397 | /** |
||
398 | * Sets the contents of a file to the specified value. |
||
399 | * |
||
400 | * @param string $fileIdentifier |
||
401 | * @param string $contents |
||
402 | * @return int The number of bytes written to the file |
||
403 | */ |
||
404 | 3 | public function setFileContents($fileIdentifier, $contents) |
|
410 | |||
411 | /** |
||
412 | * Checks if a file inside a folder exists |
||
413 | * |
||
414 | * @param string $fileName |
||
415 | * @param string $folderIdentifier |
||
416 | * @return bool |
||
417 | */ |
||
418 | 3 | public function fileExistsInFolder($fileName, $folderIdentifier) |
|
424 | |||
425 | /** |
||
426 | * Checks if a folder inside a folder exists. |
||
427 | * |
||
428 | * @param string $folderName |
||
429 | * @param string $folderIdentifier |
||
430 | * @return bool |
||
431 | */ |
||
432 | public function folderExistsInFolder($folderName, $folderIdentifier) |
||
436 | |||
437 | /** |
||
438 | * Returns a path to a local copy of a file for processing it. When changing the |
||
439 | * file, you have to take care of replacing the current version yourself! |
||
440 | * |
||
441 | * @param string $fileIdentifier |
||
442 | * @param bool $writable Set this to FALSE if you only need the file for read |
||
443 | * operations. This might speed up things, e.g. by using |
||
444 | * a cached local version. Never modify the file if you |
||
445 | * have set this flag! |
||
446 | * @return string The path to the file on the local disk |
||
447 | */ |
||
448 | public function getFileForLocalProcessing($fileIdentifier, $writable = true) |
||
456 | |||
457 | /** |
||
458 | * Returns the permissions of a file/folder as an array |
||
459 | * (keys r, w) of boolean flags |
||
460 | * |
||
461 | * @param string $identifier |
||
462 | * @return array |
||
463 | */ |
||
464 | public function getPermissions($identifier) |
||
471 | |||
472 | /** |
||
473 | * Directly output the contents of the file to the output |
||
474 | * buffer. Should not take care of header files or flushing |
||
475 | * buffer before. Will be taken care of by the Storage. |
||
476 | * |
||
477 | * @param string $identifier |
||
478 | * @return void |
||
479 | */ |
||
480 | public function dumpFileContents($identifier) |
||
487 | |||
488 | /** |
||
489 | * Checks if a given identifier is within a container, e.g. if |
||
490 | * a file or folder is within another folder. |
||
491 | * This can e.g. be used to check for web-mounts. |
||
492 | * |
||
493 | * Hint: this also needs to return TRUE if the given identifier |
||
494 | * matches the container identifier to allow access to the root |
||
495 | * folder of a filemount. |
||
496 | * |
||
497 | * @param string $folderIdentifier |
||
498 | * @param string $identifier identifier to be checked against $folderIdentifier |
||
499 | * @return bool TRUE if $content is within or matches $folderIdentifier |
||
500 | */ |
||
501 | public function isWithin($folderIdentifier, $identifier) |
||
515 | |||
516 | /** |
||
517 | * Returns information about a file. |
||
518 | * |
||
519 | * @param string $fileIdentifier |
||
520 | * @param array $propertiesToExtract Array of properties which are be extracted |
||
521 | * If empty all will be extracted |
||
522 | * @return array |
||
523 | */ |
||
524 | public function getFileInfoByIdentifier($fileIdentifier, array $propertiesToExtract = []) |
||
534 | |||
535 | /** |
||
536 | * Returns information about a file. |
||
537 | * |
||
538 | * @param string $folderIdentifier |
||
539 | * @return array |
||
540 | */ |
||
541 | public function getFolderInfoByIdentifier($folderIdentifier) |
||
551 | |||
552 | /** |
||
553 | * Returns the identifier of a file inside the folder |
||
554 | * |
||
555 | * @param string $fileName |
||
556 | * @param string $folderIdentifier |
||
557 | * @return string file identifier |
||
558 | */ |
||
559 | public function getFileInFolder($fileName, $folderIdentifier) |
||
563 | |||
564 | /** |
||
565 | * Returns a list of files inside the specified path |
||
566 | * |
||
567 | * @param string $folderIdentifier |
||
568 | * @param int $start |
||
569 | * @param int $numberOfItems |
||
570 | * @param bool $recursive |
||
571 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
572 | * @param string $sort Property name used to sort the items. |
||
573 | * Among them may be: '' (empty, no sorting), name, |
||
574 | * fileext, size, tstamp and rw. |
||
575 | * If a driver does not support the given property, it |
||
576 | * should fall back to "name". |
||
577 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
578 | * @return array of FileIdentifiers |
||
579 | */ |
||
580 | 3 | public function getFilesInFolder( |
|
604 | |||
605 | /** |
||
606 | * Returns the identifier of a folder inside the folder |
||
607 | * |
||
608 | * @param string $folderName The name of the target folder |
||
609 | * @param string $folderIdentifier |
||
610 | * @return string folder identifier |
||
611 | */ |
||
612 | public function getFolderInFolder($folderName, $folderIdentifier) |
||
617 | |||
618 | /** |
||
619 | * Returns a list of folders inside the specified path |
||
620 | * |
||
621 | * @param string $folderIdentifier |
||
622 | * @param int $start |
||
623 | * @param int $numberOfItems |
||
624 | * @param bool $recursive |
||
625 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
626 | * @param string $sort Property name used to sort the items. |
||
627 | * Among them may be: '' (empty, no sorting), name, |
||
628 | * fileext, size, tstamp and rw. |
||
629 | * If a driver does not support the given property, it |
||
630 | * should fall back to "name". |
||
631 | * @param bool $sortRev TRUE to indicate reverse sorting (last to first) |
||
632 | * @return array of Folder Identifier |
||
633 | * @TODO: Implement pagination with $start and $numberOfItems |
||
634 | * @TODO: Implement directory filter callbacks |
||
635 | * @TODO: Implement sorting |
||
636 | */ |
||
637 | 3 | public function getFoldersInFolder( |
|
662 | |||
663 | /** |
||
664 | * Returns the number of files inside the specified path |
||
665 | * |
||
666 | * @param string $folderIdentifier |
||
667 | * @param bool $recursive |
||
668 | * @param array $filenameFilterCallbacks callbacks for filtering the items |
||
669 | * @return int Number of files in folder |
||
670 | * @TODO: Implement recursive count |
||
671 | * @TODO: Implement filename filtering |
||
672 | */ |
||
673 | public function countFilesInFolder($folderIdentifier, $recursive = false, array $filenameFilterCallbacks = []) |
||
678 | |||
679 | /** |
||
680 | * Returns the number of folders inside the specified path |
||
681 | * |
||
682 | * @param string $folderIdentifier |
||
683 | * @param bool $recursive |
||
684 | * @param array $folderNameFilterCallbacks callbacks for filtering the items |
||
685 | * @return int Number of folders in folder |
||
686 | */ |
||
687 | 3 | public function countFoldersInFolder($folderIdentifier, $recursive = false, array $folderNameFilterCallbacks = []) |
|
700 | |||
701 | /** |
||
702 | * Extracts information about a file from the filesystem. |
||
703 | * |
||
704 | * @param string $filePath The absolute path to the file |
||
705 | * @param string $containerPath The relative path to the file's container |
||
706 | * @param array $propertiesToExtract array of properties which should be returned, if empty all will be extracted |
||
707 | * @return array |
||
708 | */ |
||
709 | protected function extractFileInformation($filePath, $containerPath, array $propertiesToExtract = array()) |
||
732 | |||
733 | /** |
||
734 | * Extracts a specific FileInformation from the FileSystems. |
||
735 | * |
||
736 | * @param string $fileIdentifier |
||
737 | * @param string $containerPath |
||
738 | * @param string $property |
||
739 | * |
||
740 | * @return bool|int|string |
||
741 | * @throws \InvalidArgumentException |
||
742 | */ |
||
743 | public function getSpecificFileInformation($fileIdentifier, $containerPath, $property) |
||
773 | } |
||
774 |