Complex classes like Console 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 Console, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
19 | class Console |
||
20 | { |
||
21 | /** |
||
22 | * @var CLImate |
||
23 | */ |
||
24 | protected $engine; |
||
25 | |||
26 | /** |
||
27 | * @param CLImate $engine |
||
28 | */ |
||
29 | public function __construct(CLImate $engine) |
||
33 | |||
34 | /** |
||
35 | * Add literal art directory |
||
36 | * |
||
37 | * @param string $dir |
||
38 | * @return $this |
||
39 | */ |
||
40 | public function addArt($dir) |
||
45 | |||
46 | /** |
||
47 | * Clear screen |
||
48 | * |
||
49 | * @return $this |
||
50 | */ |
||
51 | public function clear() |
||
56 | |||
57 | /** |
||
58 | * Black text color |
||
59 | * |
||
60 | * @param string|null $str |
||
61 | * @return $this |
||
62 | */ |
||
63 | public function black($str = null) |
||
68 | |||
69 | /** |
||
70 | * Red text color |
||
71 | * |
||
72 | * @param string|null $str |
||
73 | * @return $this |
||
74 | */ |
||
75 | public function red($str = null) |
||
80 | |||
81 | /** |
||
82 | * Green text color |
||
83 | * |
||
84 | * @param string|null $str |
||
85 | * @return $this |
||
86 | */ |
||
87 | public function green($str = null) |
||
92 | |||
93 | /** |
||
94 | * Yellow text color |
||
95 | * |
||
96 | * @param string|null $str |
||
97 | * @return $this |
||
98 | */ |
||
99 | public function yellow($str = null) |
||
104 | |||
105 | /** |
||
106 | * Blue text color |
||
107 | * |
||
108 | * @param string|null $str |
||
109 | * @return $this |
||
110 | */ |
||
111 | public function blue($str = null) |
||
116 | |||
117 | /** |
||
118 | * Magenta text color |
||
119 | * |
||
120 | * @param string|null $str |
||
121 | * @return $this |
||
122 | */ |
||
123 | public function magenta($str = null) |
||
128 | |||
129 | /** |
||
130 | * Cyan text color |
||
131 | * |
||
132 | * @param string|null $str |
||
133 | * @return $this |
||
134 | */ |
||
135 | public function cyan($str = null) |
||
140 | |||
141 | /** |
||
142 | * Light gray text color |
||
143 | * |
||
144 | * @param string|null $str |
||
145 | * @return $this |
||
146 | */ |
||
147 | public function lightGray($str = null) |
||
152 | |||
153 | /** |
||
154 | * Dark gray text color |
||
155 | * |
||
156 | * @param string|null $str |
||
157 | * @return $this |
||
158 | */ |
||
159 | public function darkGray($str = null) |
||
164 | |||
165 | /** |
||
166 | * Light red text color |
||
167 | * |
||
168 | * @param string|null $str |
||
169 | * @return $this |
||
170 | */ |
||
171 | public function lightRed($str = null) |
||
176 | |||
177 | /** |
||
178 | * Light green text color |
||
179 | * |
||
180 | * @param string|null $str |
||
181 | * @return $this |
||
182 | */ |
||
183 | public function lightGreen($str = null) |
||
188 | |||
189 | /** |
||
190 | * Light yellow text color |
||
191 | * |
||
192 | * @param string|null $str |
||
193 | * @return $this |
||
194 | */ |
||
195 | public function lightYellow($str = null) |
||
200 | |||
201 | /** |
||
202 | * Light blue text color |
||
203 | * |
||
204 | * @param string|null $str |
||
205 | * @return $this |
||
206 | */ |
||
207 | public function lightBlue($str = null) |
||
212 | |||
213 | /** |
||
214 | * Light magenta text color |
||
215 | * |
||
216 | * @param string|null $str |
||
217 | * @return $this |
||
218 | */ |
||
219 | public function lightMagenta($str = null) |
||
224 | |||
225 | /** |
||
226 | * Light cyan text color |
||
227 | * |
||
228 | * @param string|null $str |
||
229 | * @return $this |
||
230 | */ |
||
231 | public function lightCyan($str = null) |
||
236 | |||
237 | /** |
||
238 | * White text color |
||
239 | * |
||
240 | * @param string|null $str |
||
241 | * @return $this |
||
242 | */ |
||
243 | public function white($str = null) |
||
248 | |||
249 | /** |
||
250 | * Black background color |
||
251 | * |
||
252 | * @param string|null $str |
||
253 | * @return $this |
||
254 | */ |
||
255 | public function blackBg($str = null) |
||
260 | |||
261 | /** |
||
262 | * Red background color |
||
263 | * |
||
264 | * @param string|null $str |
||
265 | * @return $this |
||
266 | */ |
||
267 | public function redBg($str = null) |
||
272 | |||
273 | /** |
||
274 | * Green background color |
||
275 | * |
||
276 | * @param string|null $str |
||
277 | * @return $this |
||
278 | */ |
||
279 | public function greenBg($str = null) |
||
284 | |||
285 | /** |
||
286 | * Yellow background color |
||
287 | * |
||
288 | * @param string|null $str |
||
289 | * @return $this |
||
290 | */ |
||
291 | public function yellowBg($str = null) |
||
296 | |||
297 | /** |
||
298 | * Blue background color |
||
299 | * |
||
300 | * @param string|null $str |
||
301 | * @return $this |
||
302 | */ |
||
303 | public function blueBg($str = null) |
||
308 | |||
309 | /** |
||
310 | * Magenta background color |
||
311 | * |
||
312 | * @param string|null $str |
||
313 | * @return $this |
||
314 | */ |
||
315 | public function magentaBg($str = null) |
||
320 | |||
321 | /** |
||
322 | * Cyan background color |
||
323 | * |
||
324 | * @param string|null $str |
||
325 | * @return $this |
||
326 | */ |
||
327 | public function cyanBg($str = null) |
||
332 | |||
333 | /** |
||
334 | * Light gray background color |
||
335 | * |
||
336 | * @param string|null $str |
||
337 | * @return $this |
||
338 | */ |
||
339 | public function lightGrayBg($str = null) |
||
344 | |||
345 | /** |
||
346 | * Dark gray background color |
||
347 | * |
||
348 | * @param string|null $str |
||
349 | * @return $this |
||
350 | */ |
||
351 | public function darkGrayBg($str = null) |
||
356 | |||
357 | /** |
||
358 | * Light red background color |
||
359 | * |
||
360 | * @param string|null $str |
||
361 | * @return $this |
||
362 | */ |
||
363 | public function lightRedBg($str = null) |
||
368 | |||
369 | /** |
||
370 | * Light green background color |
||
371 | * |
||
372 | * @param string|null $str |
||
373 | * @return $this |
||
374 | */ |
||
375 | public function lightGreenBg($str = null) |
||
380 | |||
381 | /** |
||
382 | * Light yellow background color |
||
383 | * |
||
384 | * @param string|null $str |
||
385 | * @return $this |
||
386 | */ |
||
387 | public function lightYellowBg($str = null) |
||
392 | |||
393 | /** |
||
394 | * Light blue background color |
||
395 | * |
||
396 | * @param string|null $str |
||
397 | * @return $this |
||
398 | */ |
||
399 | public function lightBlueBg($str = null) |
||
404 | |||
405 | /** |
||
406 | * Light magenta background color |
||
407 | * |
||
408 | * @param string|null $str |
||
409 | * @return $this |
||
410 | */ |
||
411 | public function lightMagentaBg($str = null) |
||
416 | |||
417 | /** |
||
418 | * Light cyan background color |
||
419 | * |
||
420 | * @param string|null $str |
||
421 | * @return $this |
||
422 | */ |
||
423 | public function lightCyanBg($str = null) |
||
428 | |||
429 | /** |
||
430 | * White background color |
||
431 | * |
||
432 | * @param string|null $str |
||
433 | * @return $this |
||
434 | */ |
||
435 | public function whiteBg($str = null) |
||
440 | |||
441 | /** |
||
442 | * Bold text |
||
443 | * |
||
444 | * @param string|null $str |
||
445 | * @return $this |
||
446 | */ |
||
447 | public function bold($str = null) |
||
452 | |||
453 | /** |
||
454 | * Dimmed text |
||
455 | * |
||
456 | * @param string|null $str |
||
457 | * @return $this |
||
458 | */ |
||
459 | public function dim($str = null) |
||
464 | |||
465 | /** |
||
466 | * Underlined text |
||
467 | * |
||
468 | * @param string|null $str |
||
469 | * @return $this |
||
470 | */ |
||
471 | public function underline($str = null) |
||
476 | |||
477 | /** |
||
478 | * Inverted text |
||
479 | * |
||
480 | * @param string|null $str |
||
481 | * @return $this |
||
482 | */ |
||
483 | public function invert($str = null) |
||
488 | |||
489 | /** |
||
490 | * Info text |
||
491 | * |
||
492 | * @param string|null $str |
||
493 | * @return $this |
||
494 | */ |
||
495 | public function info($str = null) |
||
500 | |||
501 | /** |
||
502 | * Comment text |
||
503 | * |
||
504 | * @param string|null $str |
||
505 | * @return $this |
||
506 | */ |
||
507 | public function comment($str = null) |
||
512 | |||
513 | /** |
||
514 | * Whispered text |
||
515 | * |
||
516 | * @param string|null $str |
||
517 | * @return $this |
||
518 | */ |
||
519 | public function whisper($str = null) |
||
524 | |||
525 | /** |
||
526 | * Shouted text |
||
527 | * |
||
528 | * @param string|null $str |
||
529 | * @return $this |
||
530 | */ |
||
531 | public function shout($str = null) |
||
536 | |||
537 | /** |
||
538 | * Error text |
||
539 | * |
||
540 | * @param string|null $str |
||
541 | * @return $this |
||
542 | */ |
||
543 | public function error($str = null) |
||
548 | |||
549 | /** |
||
550 | * Data columns |
||
551 | * |
||
552 | * @param array $data |
||
553 | * @param int|null $columnCount |
||
554 | * @return $this |
||
555 | */ |
||
556 | public function columns(array $data, $columnCount = null) |
||
561 | |||
562 | /** |
||
563 | * Text output |
||
564 | * |
||
565 | * @param string $str |
||
566 | * @return $this |
||
567 | */ |
||
568 | public function out($str) |
||
573 | |||
574 | /** |
||
575 | * Inline text output |
||
576 | * |
||
577 | * @param string $str |
||
578 | * @return $this |
||
579 | */ |
||
580 | public function inline($str) |
||
585 | |||
586 | /** |
||
587 | * Data table |
||
588 | * |
||
589 | * @param array $data |
||
590 | * @return $this |
||
591 | */ |
||
592 | public function table(array $data) |
||
597 | |||
598 | /** |
||
599 | * JSON data |
||
600 | * |
||
601 | * @param mixed $var |
||
602 | * @return $this |
||
603 | */ |
||
604 | public function json($var) |
||
609 | |||
610 | /** |
||
611 | * Space |
||
612 | * |
||
613 | * @param int $count |
||
614 | * @return $this |
||
615 | */ |
||
616 | public function sp($count = 1) |
||
623 | |||
624 | /** |
||
625 | * New line |
||
626 | * |
||
627 | * @param int $count |
||
628 | * @return $this |
||
629 | */ |
||
630 | public function br($count = 1) |
||
635 | |||
636 | /** |
||
637 | * Tabulator |
||
638 | * |
||
639 | * @param int $count |
||
640 | * @return $this |
||
641 | */ |
||
642 | public function tab($count = 1) |
||
647 | |||
648 | /** |
||
649 | * Draw art |
||
650 | * |
||
651 | * @param string $art |
||
652 | * @return $this |
||
653 | */ |
||
654 | public function draw($art) |
||
659 | |||
660 | /** |
||
661 | * Literal border |
||
662 | * |
||
663 | * @param string|null $char |
||
664 | * @param int|null $length |
||
665 | * @return $this |
||
666 | */ |
||
667 | public function border($char = null, $length = null) |
||
672 | |||
673 | /** |
||
674 | * Variable debug |
||
675 | * |
||
676 | * @param mixed $var |
||
677 | * @return $this |
||
678 | */ |
||
679 | public function dump($var) |
||
684 | |||
685 | /** |
||
686 | * Literal strong text |
||
687 | * |
||
688 | * @param string $output |
||
689 | * @param string|null $char |
||
690 | * @param int|null $length |
||
691 | * @return $this |
||
692 | */ |
||
693 | public function flank($output, $char = null, $length = null) |
||
698 | |||
699 | /** |
||
700 | * Progress bar |
||
701 | * |
||
702 | * @param int|null $total |
||
703 | * @return Dynamic\Progress |
||
704 | */ |
||
705 | public function progress($total = null) |
||
709 | |||
710 | /** |
||
711 | * Left literal padding |
||
712 | * |
||
713 | * @param int $length |
||
714 | * @param string $char |
||
715 | * @return Dynamic\Padding |
||
716 | */ |
||
717 | public function padding($length = 0, $char = '.') |
||
721 | |||
722 | /** |
||
723 | * Optional input text |
||
724 | * |
||
725 | * @param string $prompt |
||
726 | * @return Dynamic\Input |
||
727 | */ |
||
728 | public function input($prompt) |
||
732 | |||
733 | /** |
||
734 | * Confirmation input text |
||
735 | * |
||
736 | * @param string $prompt |
||
737 | * @return Dynamic\Confirm |
||
738 | */ |
||
739 | public function confirm($prompt) |
||
743 | |||
744 | /** |
||
745 | * Password input text |
||
746 | * |
||
747 | * @param string $prompt |
||
748 | * @return Dynamic\Password |
||
749 | */ |
||
750 | public function password($prompt) |
||
754 | |||
755 | /** |
||
756 | * Multi-option input text |
||
757 | * |
||
758 | * @param string $prompt |
||
759 | * @param array $options |
||
760 | * @return Dynamic\Checkboxes |
||
761 | */ |
||
762 | public function checkboxes($prompt, array $options) |
||
766 | |||
767 | /** |
||
768 | * Single-option input text |
||
769 | * |
||
770 | * @param string $prompt |
||
771 | * @param array $options |
||
772 | * @return Dynamic\Radio |
||
773 | */ |
||
774 | public function radio($prompt, array $options) |
||
778 | |||
779 | /** |
||
780 | * Play an animation |
||
781 | * |
||
782 | * @param string $art |
||
783 | * @return Dynamic\Animation |
||
784 | */ |
||
785 | public function animation($art) |
||
789 | } |
||
790 |