Complex classes like OutputAware 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 OutputAware, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 7 | trait OutputAware |
||
| 8 | { |
||
| 9 | protected |
||
| 10 | $output = null; |
||
| 11 | |||
| 12 | public function setOutput(OutputInterface $output) |
||
| 18 | |||
| 19 | protected function error($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
||
| 23 | |||
| 24 | protected function warning($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
||
| 28 | |||
| 29 | protected function info($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
||
| 33 | |||
| 34 | protected function debug($messages, $newline = false, $type = OutputInterface::OUTPUT_NORMAL) |
||
| 38 | |||
| 39 | private function write($messages, $newline, $type, $verbosity, $textColor) |
||
| 58 | } |