Complex classes like Repository 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 Repository, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 49 | class Repository extends AbstractRepository |
||
| 50 | { |
||
| 51 | /** |
||
| 52 | * The SVN binary |
||
| 53 | * |
||
| 54 | * @var Binary |
||
| 55 | */ |
||
| 56 | protected $svn; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * Opens a SVN repository on the file system |
||
| 60 | * |
||
| 61 | * @param string $repositoryPath The full path to the repository |
||
| 62 | * @param Binary|string|null $svn The SVN binary |
||
| 63 | * @return Repository |
||
| 64 | * @throws \RuntimeException If the path cannot be created |
||
| 65 | * @throws \InvalidArgumentException If the path is not valid or if it's not a valid SVN repository |
||
| 66 | */ |
||
| 67 | 94 | public static function open($repositoryPath, $svn = null) |
|
| 87 | |||
| 88 | /** |
||
| 89 | * Tries to find the root directory for a given repository path |
||
| 90 | * |
||
| 91 | * @param Binary $svn The SVN binary |
||
| 92 | * @param string $path The file system path |
||
| 93 | * @return string|null NULL if the root cannot be found, the root path otherwise |
||
| 94 | */ |
||
| 95 | public static function findRepositoryRoot(Binary $svn, $path) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Creates a new repository instance - use {@see open()} instead |
||
| 115 | * |
||
| 116 | * @param string $repositoryPath |
||
| 117 | * @param Binary $svn |
||
| 118 | */ |
||
| 119 | 92 | protected function __construct($repositoryPath, Binary $svn) |
|
| 124 | |||
| 125 | /** |
||
| 126 | * Returns the SVN binary |
||
| 127 | * |
||
| 128 | * @return Binary |
||
| 129 | */ |
||
| 130 | 73 | public function getSvn() |
|
| 134 | |||
| 135 | /** |
||
| 136 | * Returns the current commit hash |
||
| 137 | * |
||
| 138 | * @return string |
||
| 139 | * @throws \RuntimeException |
||
| 140 | */ |
||
| 141 | 52 | public function getCurrentCommit() |
|
| 163 | |||
| 164 | /** |
||
| 165 | * Commits the currently staged changes into the repository |
||
| 166 | * |
||
| 167 | * @param string $commitMsg The commit message |
||
| 168 | * @param array|null $file Restrict commit to the given files or NULL to commit all staged changes |
||
| 169 | * @param array $extraArgs Allow the user to pass extra args eg array('-i') |
||
| 170 | * @param string|null $author The author |
||
| 171 | */ |
||
| 172 | 53 | public function commit($commitMsg, array $file = null, $author = null, array $extraArgs = array()) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * Resets the working directory and/or the staging area and discards all changes |
||
| 193 | * |
||
| 194 | * @throws \RuntimeException |
||
| 195 | */ |
||
| 196 | 2 | public function reset() |
|
| 214 | |||
| 215 | /** |
||
| 216 | * Adds one or more files to the staging area |
||
| 217 | * |
||
| 218 | * @param array $file The file(s) to be added or NULL to add all new and/or changed files to the staging area |
||
| 219 | * @param boolean $force |
||
| 220 | */ |
||
| 221 | 40 | public function add(array $file = null, $force = false) |
|
| 278 | |||
| 279 | /** |
||
| 280 | * Removes one or more files from the repository but does not commit the changes |
||
| 281 | * |
||
| 282 | * @param array $file The file(s) to be removed |
||
| 283 | * @param boolean $recursive True to recursively remove subdirectories |
||
| 284 | * @param boolean $force True to continue even though SVN reports a possible conflict |
||
| 285 | */ |
||
| 286 | 11 | public function remove(array $file, $recursive = false, $force = false) |
|
| 301 | |||
| 302 | /** |
||
| 303 | * Renames a file but does not commit the changes |
||
| 304 | * |
||
| 305 | * @param string $fromPath The source path |
||
| 306 | * @param string $toPath The destination path |
||
| 307 | * @param boolean $force True to continue even though SVN reports a possible conflict |
||
| 308 | */ |
||
| 309 | 8 | public function move($fromPath, $toPath, $force = false) |
|
| 324 | |||
| 325 | /** |
||
| 326 | * Writes data to a file and commit the changes immediately |
||
| 327 | * |
||
| 328 | * @param string $path The file path |
||
| 329 | * @param string|array $data The data to write to the file |
||
| 330 | * @param string|null $commitMsg The commit message used when committing the changes |
||
| 331 | * @param integer|null $fileMode The mode for creating the file |
||
| 332 | * @param integer|null $dirMode The mode for creating the intermediate directories |
||
| 333 | * @param boolean $recursive Create intermediate directories recursively if required |
||
| 334 | * @param string|null $author The author |
||
| 335 | * @return string The current commit hash |
||
| 336 | * @throws \RuntimeException If the file could not be written |
||
| 337 | */ |
||
| 338 | 21 | public function writeFile($path, $data, $commitMsg = null, $fileMode = null, |
|
| 372 | |||
| 373 | /** |
||
| 374 | * Writes data to a file and commit the changes immediately |
||
| 375 | * |
||
| 376 | * @param string $path The directory path |
||
| 377 | * @param string|null $commitMsg The commit message used when committing the changes |
||
| 378 | * @param integer|null $dirMode The mode for creating the intermediate directories |
||
| 379 | * @param boolean $recursive Create intermediate directories recursively if required |
||
| 380 | * @param string|null $author The author |
||
| 381 | * @return string The current commit hash |
||
| 382 | * @throws \RuntimeException If the directory could not be created |
||
| 383 | */ |
||
| 384 | 4 | public function createDirectory($path, $commitMsg = null, $dirMode = null, $recursive = true, $author = null) { |
|
| 402 | |||
| 403 | /** |
||
| 404 | * Removes a file and commit the changes immediately |
||
| 405 | * |
||
| 406 | * @param string $path The file path |
||
| 407 | * @param string|null $commitMsg The commit message used when committing the changes |
||
| 408 | * @param boolean $recursive True to recursively remove subdirectories |
||
| 409 | * @param boolean $force True to continue even though SVN reports a possible conflict |
||
| 410 | * @param string|null $author The author |
||
| 411 | * @return string The current commit hash |
||
| 412 | */ |
||
| 413 | 10 | public function removeFile($path, $commitMsg = null, $recursive = false, $force = false, $author = null) |
|
| 425 | |||
| 426 | /** |
||
| 427 | * Renames a file and commit the changes immediately |
||
| 428 | * |
||
| 429 | * @param string $fromPath The source path |
||
| 430 | * @param string $toPath The destination path |
||
| 431 | * @param string|null $commitMsg The commit message used when committing the changes |
||
| 432 | * @param boolean $force True to continue even though SVN reports a possible conflict |
||
| 433 | * @param string|null $author The author |
||
| 434 | * @return string The current commit hash |
||
| 435 | */ |
||
| 436 | 8 | public function renameFile($fromPath, $toPath, $commitMsg = null, $force = false, $author = null) |
|
| 448 | |||
| 449 | /** |
||
| 450 | * Returns the current repository log |
||
| 451 | * |
||
| 452 | * @param integer|null $limit The maximum number of log entries returned |
||
| 453 | * @param integer|null $skip Number of log entries that are skipped from the beginning |
||
| 454 | * @return array |
||
| 455 | * @throws \RuntimeException |
||
| 456 | */ |
||
| 457 | 2 | public function getLog($limit = null, $skip = null) |
|
| 497 | |||
| 498 | /** |
||
| 499 | * Returns a string containing information about the given commit |
||
| 500 | * |
||
| 501 | * @param string $hash The commit ref |
||
| 502 | * @return string |
||
| 503 | */ |
||
| 504 | 40 | public function showCommit($hash) |
|
| 517 | |||
| 518 | /** |
||
| 519 | * Returns the content of a file at a given version |
||
| 520 | * |
||
| 521 | * @param string $file The path to the file |
||
| 522 | * @param string $ref The version ref |
||
| 523 | * @return string |
||
| 524 | */ |
||
| 525 | 3 | public function showFile($file, $ref = 'HEAD') |
|
| 538 | |||
| 539 | /** |
||
| 540 | * Returns information about an object at a given version |
||
| 541 | * |
||
| 542 | * The information returned is an array with the following structure |
||
| 543 | * array( |
||
| 544 | * 'type' => blob|tree|commit, |
||
| 545 | * 'mode' => 0040000 for a tree, 0100000 for a blob, 0 otherwise, |
||
| 546 | * 'size' => the size |
||
| 547 | * ) |
||
| 548 | * |
||
| 549 | * @param string $path The path to the object |
||
| 550 | * @param string $ref The version ref |
||
| 551 | * @return array The object info |
||
| 552 | * @throws \RuntimeException |
||
| 553 | */ |
||
| 554 | 4 | public function getObjectInfo($path, $ref = 'HEAD') |
|
| 595 | |||
| 596 | /** |
||
| 597 | * List the directory at a given version |
||
| 598 | * |
||
| 599 | * @param string $directory The path ot the directory |
||
| 600 | * @param string $ref The version ref |
||
| 601 | * @return array |
||
| 602 | * @throws \RuntimeException |
||
| 603 | */ |
||
| 604 | 12 | public function listDirectory($directory = '.', $ref = 'HEAD') |
|
| 634 | |||
| 635 | /** |
||
| 636 | * Returns the current status of the working directory |
||
| 637 | * |
||
| 638 | * The returned array structure is |
||
| 639 | * array( |
||
| 640 | * 'file' => '...', |
||
| 641 | * 'status' => '...' |
||
| 642 | * ) |
||
| 643 | * |
||
| 644 | * @return array |
||
| 645 | * @throws \RuntimeException |
||
| 646 | */ |
||
| 647 | 52 | public function getStatus() |
|
| 671 | |||
| 672 | /** |
||
| 673 | * Returns the diff of a file |
||
| 674 | * |
||
| 675 | * @param array $files The path to the file |
||
| 676 | * @return string[] |
||
| 677 | */ |
||
| 678 | 1 | public function getDiff(array $files = null) |
|
| 709 | |||
| 710 | /** |
||
| 711 | * Returns true if there are uncommitted changes in the working directory and/or the staging area |
||
| 712 | * |
||
| 713 | * @return boolean |
||
| 714 | */ |
||
| 715 | 31 | public function isDirty() |
|
| 720 | |||
| 721 | /** |
||
| 722 | * Resolves an absolute path containing glob wildcards into a path relative to the repository path |
||
| 723 | * |
||
| 724 | * @param array $files The list of files |
||
| 725 | * @return array |
||
| 726 | */ |
||
| 727 | 53 | protected function resolveLocalGlobPath(array $files) |
|
| 744 | } |
||
| 745 | |||
| 746 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.