Complex classes like Connector 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 Connector, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 23 | class Connector |
||
| 24 | { |
||
| 25 | |||
| 26 | const STATUS_UNVERSIONED = 'unversioned'; |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Reference to configuration. |
||
| 30 | * |
||
| 31 | * @var ConfigEditor |
||
| 32 | */ |
||
| 33 | private $_configEditor; |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Process factory. |
||
| 37 | * |
||
| 38 | * @var IProcessFactory |
||
| 39 | */ |
||
| 40 | private $_processFactory; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Console IO. |
||
| 44 | * |
||
| 45 | * @var ConsoleIO |
||
| 46 | */ |
||
| 47 | private $_io; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Cache manager. |
||
| 51 | * |
||
| 52 | * @var CacheManager |
||
| 53 | */ |
||
| 54 | private $_cacheManager; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Path to an svn command. |
||
| 58 | * |
||
| 59 | * @var string |
||
| 60 | */ |
||
| 61 | private $_svnCommand = 'svn'; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Cache duration for next invoked command. |
||
| 65 | * |
||
| 66 | * @var mixed |
||
| 67 | */ |
||
| 68 | private $_nextCommandCacheDuration = null; |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Whatever to cache last repository revision or not. |
||
| 72 | * |
||
| 73 | * @var mixed |
||
| 74 | */ |
||
| 75 | private $_lastRevisionCacheDuration = null; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Creates repository connector. |
||
| 79 | * |
||
| 80 | * @param ConfigEditor $config_editor ConfigEditor. |
||
| 81 | * @param IProcessFactory $process_factory Process factory. |
||
| 82 | * @param ConsoleIO $io Console IO. |
||
| 83 | * @param CacheManager $cache_manager Cache manager. |
||
| 84 | */ |
||
| 85 | 47 | public function __construct( |
|
| 106 | |||
| 107 | /** |
||
| 108 | * Prepares static part of svn command to be used across the script. |
||
| 109 | * |
||
| 110 | * @return void |
||
| 111 | */ |
||
| 112 | 47 | protected function prepareSvnCommand() |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Builds a command. |
||
| 130 | * |
||
| 131 | * @param string $sub_command Sub command. |
||
| 132 | * @param string|null $param_string Parameter string. |
||
| 133 | * |
||
| 134 | * @return Command |
||
| 135 | */ |
||
| 136 | 29 | public function getCommand($sub_command, $param_string = null) |
|
| 153 | |||
| 154 | /** |
||
| 155 | * Builds command from given arguments. |
||
| 156 | * |
||
| 157 | * @param string $sub_command Command. |
||
| 158 | * @param string $param_string Parameter string. |
||
| 159 | * |
||
| 160 | * @return string |
||
| 161 | * @throws \InvalidArgumentException When command contains spaces. |
||
| 162 | */ |
||
| 163 | 29 | protected function buildCommand($sub_command, $param_string = null) |
|
| 189 | |||
| 190 | /** |
||
| 191 | * Sets cache configuration for next created command. |
||
| 192 | * |
||
| 193 | * @param mixed $cache_duration Cache duration. |
||
| 194 | * |
||
| 195 | * @return self |
||
| 196 | */ |
||
| 197 | 11 | public function withCache($cache_duration) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * Returns property value. |
||
| 206 | * |
||
| 207 | * @param string $name Property name. |
||
| 208 | * @param string $path_or_url Path to get property from. |
||
| 209 | * @param mixed $revision Revision. |
||
| 210 | * |
||
| 211 | * @return string |
||
| 212 | */ |
||
| 213 | 2 | public function getProperty($name, $path_or_url, $revision = null) |
|
| 223 | |||
| 224 | /** |
||
| 225 | * Returns relative path of given path/url to the root of the repository. |
||
| 226 | * |
||
| 227 | * @param string $path_or_url Path or url. |
||
| 228 | * @param mixed $cache_duration Cache duration. |
||
| 229 | * |
||
| 230 | * @return string |
||
| 231 | */ |
||
| 232 | 3 | public function getRelativePath($path_or_url, $cache_duration = null) |
|
| 246 | |||
| 247 | /** |
||
| 248 | * Detects ref from given path. |
||
| 249 | * |
||
| 250 | * @param string $path Path to a file. |
||
| 251 | * |
||
| 252 | * @return string|boolean |
||
| 253 | */ |
||
| 254 | 6 | public function getRefByPath($path) |
|
| 262 | |||
| 263 | /** |
||
| 264 | * Returns URL of the working copy. |
||
| 265 | * |
||
| 266 | * @param string $wc_path Working copy path. |
||
| 267 | * |
||
| 268 | * @return string |
||
| 269 | * @throws RepositoryCommandException When repository command failed to execute. |
||
| 270 | */ |
||
| 271 | 7 | public function getWorkingCopyUrl($wc_path) |
|
| 298 | |||
| 299 | /** |
||
| 300 | * Returns last changed revision on path/url. |
||
| 301 | * |
||
| 302 | * @param string $path_or_url Path or url. |
||
| 303 | * @param mixed $cache_duration Cache duration. |
||
| 304 | * |
||
| 305 | * @return integer |
||
| 306 | */ |
||
| 307 | 7 | public function getLastRevision($path_or_url, $cache_duration = null) |
|
| 318 | |||
| 319 | /** |
||
| 320 | * Determines if given path is in fact an url. |
||
| 321 | * |
||
| 322 | * @param string $path Path. |
||
| 323 | * |
||
| 324 | * @return boolean |
||
| 325 | */ |
||
| 326 | 15 | public function isUrl($path) |
|
| 330 | |||
| 331 | /** |
||
| 332 | * Returns project url (container for "trunk/branches/tags/releases" folders). |
||
| 333 | * |
||
| 334 | * @param string $repository_url Repository url. |
||
| 335 | * |
||
| 336 | * @return string |
||
| 337 | */ |
||
| 338 | 9 | public function getProjectUrl($repository_url) |
|
| 346 | |||
| 347 | /** |
||
| 348 | * Returns "svn info" entry for path or url. |
||
| 349 | * |
||
| 350 | * @param string $path_or_url Path or url. |
||
| 351 | * |
||
| 352 | * @return \SimpleXMLElement |
||
| 353 | * @throws \LogicException When unexpected 'svn info' results retrieved. |
||
| 354 | */ |
||
| 355 | 16 | private function _getSvnInfoEntry($path_or_url) |
|
| 366 | |||
| 367 | /** |
||
| 368 | * Returns path of "svn info" entry. |
||
| 369 | * |
||
| 370 | * @param \SimpleXMLElement $svn_info_entry The "entry" node of "svn info" command. |
||
| 371 | * |
||
| 372 | * @return string |
||
| 373 | */ |
||
| 374 | 14 | private function _getSvnInfoEntryPath(\SimpleXMLElement $svn_info_entry) |
|
| 386 | |||
| 387 | /** |
||
| 388 | * Returns revision, when path was added to repository. |
||
| 389 | * |
||
| 390 | * @param string $url Url. |
||
| 391 | * |
||
| 392 | * @return integer |
||
| 393 | * @throws \InvalidArgumentException When not an url was given. |
||
| 394 | */ |
||
| 395 | public function getFirstRevision($url) |
||
| 405 | |||
| 406 | /** |
||
| 407 | * Returns conflicts in working copy. |
||
| 408 | * |
||
| 409 | * @param string $wc_path Working copy path. |
||
| 410 | * |
||
| 411 | * @return array |
||
| 412 | */ |
||
| 413 | public function getWorkingCopyConflicts($wc_path) |
||
| 425 | |||
| 426 | /** |
||
| 427 | * Returns compact working copy status. |
||
| 428 | * |
||
| 429 | * @param string $wc_path Working copy path. |
||
| 430 | * @param boolean $with_unversioned With unversioned. |
||
| 431 | * |
||
| 432 | * @return string |
||
| 433 | */ |
||
| 434 | public function getCompactWorkingCopyStatus($wc_path, $with_unversioned = true) |
||
| 451 | |||
| 452 | /** |
||
| 453 | * Returns short item status. |
||
| 454 | * |
||
| 455 | * @param string $status Status. |
||
| 456 | * |
||
| 457 | * @return string |
||
| 458 | * @throws \InvalidArgumentException When unknown status given. |
||
| 459 | */ |
||
| 460 | protected function getShortItemStatus($status) |
||
| 485 | |||
| 486 | /** |
||
| 487 | * Returns short item status. |
||
| 488 | * |
||
| 489 | * @param string $status Status. |
||
| 490 | * |
||
| 491 | * @return string |
||
| 492 | * @throws \InvalidArgumentException When unknown status given. |
||
| 493 | */ |
||
| 494 | protected function getShortPropertiesStatus($status) |
||
| 509 | |||
| 510 | /** |
||
| 511 | * Returns working copy status. |
||
| 512 | * |
||
| 513 | * @param string $wc_path Working copy path. |
||
| 514 | * |
||
| 515 | * @return array |
||
| 516 | */ |
||
| 517 | protected function getWorkingCopyStatus($wc_path) |
||
| 547 | |||
| 548 | /** |
||
| 549 | * Determines if working copy contains mixed revisions. |
||
| 550 | * |
||
| 551 | * @param string $wc_path Working copy path. |
||
| 552 | * |
||
| 553 | * @return array |
||
| 554 | */ |
||
| 555 | public function isMixedRevisionWorkingCopy($wc_path) |
||
| 577 | |||
| 578 | /** |
||
| 579 | * Determines if there is a working copy on a given path. |
||
| 580 | * |
||
| 581 | * @param string $path Path. |
||
| 582 | * |
||
| 583 | * @return boolean |
||
| 584 | * @throws \InvalidArgumentException When path isn't found. |
||
| 585 | * @throws RepositoryCommandException When repository command failed to execute. |
||
| 586 | */ |
||
|
1 ignored issue
–
show
|
|||
| 587 | public function isWorkingCopy($path) |
||
| 606 | |||
| 607 | } |
||
| 608 |