Complex classes like MergeCommand 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 MergeCommand, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
27 | class MergeCommand extends AbstractCommand implements IAggregatorAwareCommand, IConfigAwareCommand |
||
28 | { |
||
29 | |||
30 | const SETTING_MERGE_SOURCE_URL = 'merge.source-url'; |
||
31 | |||
32 | const SETTING_MERGE_RECENT_CONFLICTS = 'merge.recent-conflicts'; |
||
33 | |||
34 | const REVISION_ALL = 'all'; |
||
35 | |||
36 | /** |
||
37 | * Merge source detector. |
||
38 | * |
||
39 | * @var AbstractMergeSourceDetector |
||
40 | */ |
||
41 | private $_mergeSourceDetector; |
||
42 | |||
43 | /** |
||
44 | * Revision list parser. |
||
45 | * |
||
46 | * @var RevisionListParser |
||
47 | */ |
||
48 | private $_revisionListParser; |
||
49 | |||
50 | /** |
||
51 | * Unmerged revisions. |
||
52 | * |
||
53 | * @var array |
||
54 | */ |
||
55 | private $_unmergedRevisions = array(); |
||
56 | |||
57 | /** |
||
58 | * Prepare dependencies. |
||
59 | * |
||
60 | * @return void |
||
61 | */ |
||
62 | protected function prepareDependencies() |
||
71 | |||
72 | /** |
||
73 | * {@inheritdoc} |
||
|
|||
74 | */ |
||
75 | protected function configure() |
||
136 | |||
137 | /** |
||
138 | * Return possible values for the named option |
||
139 | * |
||
140 | * @param string $optionName Option name. |
||
141 | * @param CompletionContext $context Completion context. |
||
142 | * |
||
143 | * @return array |
||
144 | */ |
||
145 | public function completeOptionValues($optionName, CompletionContext $context) |
||
155 | |||
156 | /** |
||
157 | * {@inheritdoc} |
||
158 | */ |
||
159 | protected function execute(InputInterface $input, OutputInterface $output) |
||
215 | |||
216 | /** |
||
217 | * Determines if all unmerged revisions should be merged. |
||
218 | * |
||
219 | * @param array $revisions Revisions. |
||
220 | * |
||
221 | * @return boolean |
||
222 | */ |
||
223 | protected function shouldMergeAll(array $revisions) |
||
227 | |||
228 | /** |
||
229 | * Ensures, that working copy is up to date. |
||
230 | * |
||
231 | * @param string $wc_path Working copy path. |
||
232 | * |
||
233 | * @return void |
||
234 | * @throws CommandException When working copy is out of date. |
||
235 | */ |
||
236 | protected function ensureLatestWorkingCopy($wc_path) |
||
261 | |||
262 | /** |
||
263 | * Updates working copy. |
||
264 | * |
||
265 | * @param string $wc_path Working copy path. |
||
266 | * |
||
267 | * @return void |
||
268 | * @throws CommandException When unable to perform an update. |
||
269 | */ |
||
270 | protected function updateWorkingCopy($wc_path) |
||
274 | |||
275 | /** |
||
276 | * Returns source url for merge. |
||
277 | * |
||
278 | * @param string $wc_path Working copy path. |
||
279 | * |
||
280 | * @return string |
||
281 | * @throws CommandException When source path is invalid. |
||
282 | */ |
||
283 | protected function getSourceUrl($wc_path) |
||
308 | |||
309 | /** |
||
310 | * Prints information about merge source & target. |
||
311 | * |
||
312 | * @param string $source_url Merge source: url. |
||
313 | * @param string $wc_path Merge target: working copy path. |
||
314 | * |
||
315 | * @return void |
||
316 | */ |
||
317 | protected function printSourceAndTarget($source_url, $wc_path) |
||
327 | |||
328 | /** |
||
329 | * Ensures, that there are some unmerged revisions. |
||
330 | * |
||
331 | * @param string $source_url Merge source: url. |
||
332 | * @param string $wc_path Merge target: working copy path. |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | protected function getUnmergedRevisions($source_url, $wc_path) |
||
355 | |||
356 | /** |
||
357 | * Returns not merged revisions. |
||
358 | * |
||
359 | * @param string $source_url Merge source: url. |
||
360 | * @param string $wc_path Merge target: working copy path. |
||
361 | * |
||
362 | * @return array |
||
363 | */ |
||
364 | protected function calculateUnmergedRevisions($source_url, $wc_path) |
||
388 | |||
389 | /** |
||
390 | * Parses information from "svn:mergeinfo" property. |
||
391 | * |
||
392 | * @param string $source_path Merge source: path in repository. |
||
393 | * @param string $wc_path Merge target: working copy path. |
||
394 | * |
||
395 | * @return array |
||
396 | */ |
||
397 | protected function getMergedRevisions($source_path, $wc_path) |
||
412 | |||
413 | /** |
||
414 | * Validates revisions to actually exist. |
||
415 | * |
||
416 | * @param array $revisions Revisions. |
||
417 | * @param string $repository_url Repository url. |
||
418 | * |
||
419 | * @return array |
||
420 | * @throws CommandException When revision doesn't exist. |
||
421 | */ |
||
422 | protected function getDirectRevisions(array $revisions, $repository_url) |
||
439 | |||
440 | /** |
||
441 | * Performs merge. |
||
442 | * |
||
443 | * @param string $source_url Merge source: url. |
||
444 | * @param string $wc_path Merge target: working copy path. |
||
445 | * @param array $revisions Revisions to merge. |
||
446 | * |
||
447 | * @return void |
||
448 | */ |
||
449 | protected function performMerge($source_url, $wc_path, array $revisions) |
||
469 | |||
470 | /** |
||
471 | * Ensures, that there are no unresolved conflicts in working copy. |
||
472 | * |
||
473 | * @param string $source_url Source url. |
||
474 | * @param string $wc_path Working copy path. |
||
475 | * @param integer $largest_suggested_revision Largest revision, that is suggested in error message. |
||
476 | * |
||
477 | * @return void |
||
478 | * @throws CommandException When merge conflicts detected. |
||
479 | */ |
||
480 | protected function ensureWorkingCopyWithoutConflicts($source_url, $wc_path, $largest_suggested_revision = null) |
||
531 | |||
532 | /** |
||
533 | * Adds new conflicts to already remembered ones. |
||
534 | * |
||
535 | * @param array $conflicts Conflicts. |
||
536 | * |
||
537 | * @return void |
||
538 | */ |
||
539 | protected function rememberConflicts(array $conflicts) |
||
546 | |||
547 | /** |
||
548 | * Returns revisions not larger, then given one. |
||
549 | * |
||
550 | * @param array $revisions Revisions. |
||
551 | * @param integer $max_revision Maximal revision. |
||
552 | * |
||
553 | * @return array |
||
554 | */ |
||
555 | protected function limitRevisions(array $revisions, $max_revision) |
||
567 | |||
568 | /** |
||
569 | * Returns list of config settings. |
||
570 | * |
||
571 | * @return AbstractConfigSetting[] |
||
572 | */ |
||
573 | public function getConfigSettings() |
||
580 | |||
581 | } |
||
582 |