Complex classes like DropBoxDriver 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 DropBoxDriver, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class DropBoxDriver extends \elFinderVolumeMySQL implements DriverInterface |
||
|
|
|||
| 15 | { |
||
| 16 | /** @var string */ |
||
| 17 | public $name = 'DropBoxDriver'; |
||
| 18 | |||
| 19 | /** @var Connector */ |
||
| 20 | public $connector; |
||
| 21 | |||
| 22 | /** |
||
| 23 | * DropBoxDriver constructor. |
||
| 24 | */ |
||
| 25 | public function __construct() |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Gets driver name. |
||
| 32 | * @return string |
||
| 33 | */ |
||
| 34 | public function getName() |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Gets driver name. |
||
| 41 | * @param string |
||
| 42 | */ |
||
| 43 | public function setName($name) |
||
| 47 | |||
| 48 | /** |
||
| 49 | * Set connector |
||
| 50 | * @param Connector $connector |
||
| 51 | */ |
||
| 52 | public function setConnector(Connector $connector) |
||
| 56 | |||
| 57 | /** |
||
| 58 | * @return array |
||
| 59 | */ |
||
| 60 | public function getAppPluginOptions() |
||
| 64 | |||
| 65 | /** |
||
| 66 | * @return Connector |
||
| 67 | */ |
||
| 68 | public function setConnectorFromPlugin() |
||
| 73 | |||
| 74 | /** |
||
| 75 | * {@inheritdoc} |
||
| 76 | */ |
||
| 77 | public function getConfiguration() |
||
| 100 | |||
| 101 | protected function init() |
||
| 106 | |||
| 107 | /** |
||
| 108 | * Set tmp path |
||
| 109 | * |
||
| 110 | * @return void |
||
| 111 | * @author Dmitry (dio) Levashov |
||
| 112 | **/ |
||
| 113 | protected function configure() |
||
| 133 | |||
| 134 | |||
| 135 | |||
| 136 | /** |
||
| 137 | * Close connection |
||
| 138 | * |
||
| 139 | * @return void |
||
| 140 | * @author Dmitry (dio) Levashov |
||
| 141 | **/ |
||
| 142 | public function umount() |
||
| 146 | |||
| 147 | /* FS API */ |
||
| 148 | /** |
||
| 149 | * Cache dir contents |
||
| 150 | * |
||
| 151 | * @param string $path dir path |
||
| 152 | * @return void |
||
| 153 | * @author Dmitry Levashov |
||
| 154 | **/ |
||
| 155 | protected function cacheDir($path) |
||
| 176 | |||
| 177 | /***************** file stat ********************/ |
||
| 178 | /** |
||
| 179 | * Return stat for given path. |
||
| 180 | * Stat contains following fields: |
||
| 181 | * - (int) size file size in b. required |
||
| 182 | * - (int) ts file modification time in unix time. required |
||
| 183 | * - (string) mime mimetype. required for folders, others - optionally |
||
| 184 | * - (bool) read read permissions. required |
||
| 185 | * - (bool) write write permissions. required |
||
| 186 | * - (bool) locked is object locked. optionally |
||
| 187 | * - (bool) hidden is object hidden. optionally |
||
| 188 | * - (string) alias for symlinks - link target path relative to root path. optionally |
||
| 189 | * - (string) target for symlinks - link target path. optionally |
||
| 190 | * |
||
| 191 | * If file does not exists - returns empty array or false. |
||
| 192 | * |
||
| 193 | * @param string $path file path |
||
| 194 | * @return array|false |
||
| 195 | * @author Dmitry (dio) Levashov |
||
| 196 | **/ |
||
| 197 | protected function _stat($path) |
||
| 220 | |||
| 221 | /** |
||
| 222 | * @return array |
||
| 223 | */ |
||
| 224 | private function returnDirectory() |
||
| 238 | |||
| 239 | /** |
||
| 240 | * @param CDropboxFile $file |
||
| 241 | * @return array |
||
| 242 | */ |
||
| 243 | private function transformFileInStat(CDropboxFile $file) |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Return array of parents paths (ids) |
||
| 277 | * |
||
| 278 | * @param int $path file path (id) |
||
| 279 | * @return array |
||
| 280 | * @author Dmitry (dio) Levashov |
||
| 281 | **/ |
||
| 282 | protected function getParents($path) |
||
| 297 | |||
| 298 | /** |
||
| 299 | * Return correct file path for LOAD_FILE method |
||
| 300 | * |
||
| 301 | * @param string $path file path (id) |
||
| 302 | * @return string |
||
| 303 | * @author Troex Nevelin |
||
| 304 | **/ |
||
| 305 | protected function loadFilePath($path) |
||
| 313 | |||
| 314 | /** |
||
| 315 | * Recursive files search |
||
| 316 | * |
||
| 317 | * @param string $path dir path |
||
| 318 | * @param string $q search string |
||
| 319 | * @param array $mimes |
||
| 320 | * @return array |
||
| 321 | * @author Dmitry (dio) Levashov |
||
| 322 | **/ |
||
| 323 | protected function doSearch($path, $q, $mimes) |
||
| 327 | |||
| 328 | /*********************** paths/urls *************************/ |
||
| 329 | |||
| 330 | /** |
||
| 331 | * Return parent directory path |
||
| 332 | * |
||
| 333 | * @param string $path file path |
||
| 334 | * @return string |
||
| 335 | * @author Dmitry (dio) Levashov |
||
| 336 | **/ |
||
| 337 | protected function _dirname($path) |
||
| 341 | |||
| 342 | /** |
||
| 343 | * Return file name |
||
| 344 | * |
||
| 345 | * @param string $path file path |
||
| 346 | * @return string |
||
| 347 | * @author Dmitry (dio) Levashov |
||
| 348 | **/ |
||
| 349 | protected function _basename($path) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Return normalized path, this works the same as os.path.normpath() in Python |
||
| 356 | * |
||
| 357 | * @param string $path path |
||
| 358 | * @return string |
||
| 359 | * @author Troex Nevelin |
||
| 360 | **/ |
||
| 361 | protected function _normpath($path) |
||
| 365 | |||
| 366 | /** |
||
| 367 | * Return file path related to root dir |
||
| 368 | * |
||
| 369 | * @param string $path file path |
||
| 370 | * @return string |
||
| 371 | * @author Dmitry (dio) Levashov |
||
| 372 | **/ |
||
| 373 | protected function _relpath($path) |
||
| 377 | |||
| 378 | /** |
||
| 379 | * Convert path related to root dir into real path |
||
| 380 | * |
||
| 381 | * @param string $path file path |
||
| 382 | * @return string |
||
| 383 | * @author Dmitry (dio) Levashov |
||
| 384 | **/ |
||
| 385 | protected function _abspath($path) |
||
| 389 | |||
| 390 | /** |
||
| 391 | * Return fake path started from root dir |
||
| 392 | * |
||
| 393 | * @param string $path file path |
||
| 394 | * @return string |
||
| 395 | * @author Dmitry (dio) Levashov |
||
| 396 | **/ |
||
| 397 | protected function _path($path) |
||
| 411 | |||
| 412 | /** |
||
| 413 | * Return true if $path is children of $parent |
||
| 414 | * |
||
| 415 | * @param string $path path to check |
||
| 416 | * @param string $parent parent path |
||
| 417 | * @return bool |
||
| 418 | * @author Dmitry (dio) Levashov |
||
| 419 | **/ |
||
| 420 | protected function _inpath($path, $parent) |
||
| 426 | |||
| 427 | /** |
||
| 428 | * Return true if path is dir and has at least one childs directory |
||
| 429 | * |
||
| 430 | * @param string $path dir path |
||
| 431 | * @return bool |
||
| 432 | * @author Dmitry (dio) Levashov |
||
| 433 | **/ |
||
| 434 | protected function _subdirs($path) |
||
| 438 | |||
| 439 | /** |
||
| 440 | * Return object width and height |
||
| 441 | * Usualy used for images, but can be realize for video etc... |
||
| 442 | * |
||
| 443 | * @param string $path file path |
||
| 444 | * @param string $mime file mime type |
||
| 445 | * @return string |
||
| 446 | * @author Dmitry (dio) Levashov |
||
| 447 | **/ |
||
| 448 | protected function _dimensions($path, $mime) |
||
| 452 | |||
| 453 | /******************** file/dir content *********************/ |
||
| 454 | |||
| 455 | /** |
||
| 456 | * Return files list in directory. |
||
| 457 | * |
||
| 458 | * @param string $path dir path |
||
| 459 | * @return array |
||
| 460 | * @author Dmitry (dio) Levashov |
||
| 461 | **/ |
||
| 462 | protected function _scandir($path) |
||
| 468 | |||
| 469 | /** |
||
| 470 | * Open file and return file pointer |
||
| 471 | * |
||
| 472 | * @param string $path file path |
||
| 473 | * @param string $mode open file mode (ignored in this driver) |
||
| 474 | * @return resource|false |
||
| 475 | * @author Dmitry (dio) Levashov |
||
| 476 | **/ |
||
| 477 | protected function _fopen($path, $mode = 'rb') |
||
| 496 | |||
| 497 | /** |
||
| 498 | * Close opened file |
||
| 499 | * |
||
| 500 | * @param resource $fp file pointer |
||
| 501 | * @return bool |
||
| 502 | * @author Dmitry (dio) Levashov |
||
| 503 | **/ |
||
| 504 | protected function _fclose($fp, $path = '') |
||
| 511 | |||
| 512 | /******************** file/dir manipulations *************************/ |
||
| 513 | |||
| 514 | /** |
||
| 515 | * Create dir and return created dir path or false on failed |
||
| 516 | * |
||
| 517 | * @param string $path parent dir path |
||
| 518 | * @param string $name new directory name |
||
| 519 | * @return string|bool |
||
| 520 | * @author Dmitry (dio) Levashov |
||
| 521 | **/ |
||
| 522 | protected function _mkdir($path, $name) |
||
| 526 | |||
| 527 | /** |
||
| 528 | * {@inheritdoc} |
||
| 529 | */ |
||
| 530 | protected function _mkfile($path, $name) |
||
| 534 | |||
| 535 | /** |
||
| 536 | * {@inheritdoc} |
||
| 537 | */ |
||
| 538 | protected function _symlink($target, $path, $name) |
||
| 542 | |||
| 543 | /** |
||
| 544 | * {@inheritdoc} |
||
| 545 | */ |
||
| 546 | protected function _copy($source, $targetDir, $name) |
||
| 550 | |||
| 551 | /** |
||
| 552 | * {@inheritdoc} |
||
| 553 | */ |
||
| 554 | protected function _move($source, $targetDir, $name) |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Remove file |
||
| 561 | * |
||
| 562 | * @param string $path file path |
||
| 563 | * @return bool |
||
| 564 | * @author Dmitry (dio) Levashov |
||
| 565 | **/ |
||
| 566 | protected function _unlink($path) |
||
| 571 | |||
| 572 | /** |
||
| 573 | * Remove dir |
||
| 574 | * |
||
| 575 | * @param string $path dir path |
||
| 576 | * @return bool |
||
| 577 | * @author Dmitry (dio) Levashov |
||
| 578 | **/ |
||
| 579 | protected function _rmdir($path) |
||
| 584 | |||
| 585 | /** |
||
| 586 | * undocumented function |
||
| 587 | * |
||
| 588 | * @return void |
||
| 589 | * @author Dmitry Levashov |
||
| 590 | **/ |
||
| 591 | protected function _setContent($path, $fp) |
||
| 597 | |||
| 598 | /** |
||
| 599 | * {@inheritdoc} |
||
| 600 | */ |
||
| 601 | protected function _save($fp, $dir, $name, $stat) |
||
| 605 | |||
| 606 | /** |
||
| 607 | * {@inheritdoc} |
||
| 608 | */ |
||
| 609 | protected function _getContents($path) |
||
| 614 | |||
| 615 | /** |
||
| 616 | * Write a string to a file |
||
| 617 | * |
||
| 618 | * @param string $path file path |
||
| 619 | * @param string $content new file content |
||
| 620 | * @return bool |
||
| 621 | * @author Dmitry (dio) Levashov |
||
| 622 | **/ |
||
| 623 | protected function _filePutContents($path, $content) |
||
| 628 | |||
| 629 | /** |
||
| 630 | * {@inheritdoc} |
||
| 631 | */ |
||
| 632 | protected function _checkArchivers() |
||
| 636 | |||
| 637 | /** |
||
| 638 | * {@inheritdoc} |
||
| 639 | */ |
||
| 640 | protected function _unpack($path, $arc) |
||
| 644 | |||
| 645 | /** |
||
| 646 | * {@inheritdoc} |
||
| 647 | */ |
||
| 648 | protected function _findSymlinks($path) |
||
| 652 | |||
| 653 | /** |
||
| 654 | * {@inheritdoc} |
||
| 655 | */ |
||
| 656 | protected function _extract($path, $arc) |
||
| 660 | |||
| 661 | /** |
||
| 662 | * {@inheritdoc} |
||
| 663 | */ |
||
| 664 | protected function _archive($dir, $files, $name, $arc) |
||
| 668 | } |
||
| 669 |