Complex classes like PoCompiler 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 PoCompiler, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 9 | class PoCompiler |
||
| 10 | { |
||
| 11 | const TOKEN_OBSOLETE = '#~ '; |
||
| 12 | /** @var int */ |
||
| 13 | protected $wrappingColumn; |
||
| 14 | |||
| 15 | /** @var string */ |
||
| 16 | protected $lineEnding; |
||
| 17 | |||
| 18 | /** |
||
| 19 | * PoCompiler constructor. |
||
| 20 | * |
||
| 21 | * @param int $wrappingColumn |
||
| 22 | * @param string $lineEnding |
||
| 23 | */ |
||
| 24 | public function __construct($wrappingColumn = 80, $lineEnding = "\n") |
||
| 29 | |||
| 30 | /** |
||
| 31 | * Compiles entries into a string |
||
| 32 | * |
||
| 33 | * @param Catalog $catalog |
||
| 34 | * |
||
| 35 | * @return string |
||
| 36 | * @throws \Exception |
||
| 37 | * @todo Write obsolete messages at the end of the file. |
||
| 38 | */ |
||
| 39 | public function compile(Catalog $catalog) |
||
| 84 | |||
| 85 | /** |
||
| 86 | * @return string |
||
| 87 | */ |
||
| 88 | protected function eol() |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @param $entry |
||
| 95 | * |
||
| 96 | * @return string |
||
| 97 | */ |
||
| 98 | protected function buildPreviousEntry(Entry $entry) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * @param $entry |
||
| 110 | * |
||
| 111 | * @return string |
||
| 112 | */ |
||
| 113 | protected function buildTranslatorComment(Entry $entry) |
||
| 126 | |||
| 127 | protected function buildDeveloperComment(Entry $entry) |
||
| 140 | |||
| 141 | protected function buildReference(Entry $entry) |
||
| 155 | |||
| 156 | protected function buildFlags(Entry $entry) |
||
| 165 | |||
| 166 | protected function buildContext(Entry $entry) |
||
| 176 | |||
| 177 | protected function buildMsgId(Entry $entry) |
||
| 185 | |||
| 186 | protected function buildMsgStr(Entry $entry, Header $headers) |
||
| 210 | |||
| 211 | /** |
||
| 212 | * @param Entry $entry |
||
| 213 | * |
||
| 214 | * @return string |
||
| 215 | */ |
||
| 216 | protected function buildMsgIdPlural(Entry $entry) |
||
| 225 | |||
| 226 | protected function buildProperty($property, $value, $obsolete = false) |
||
| 243 | |||
| 244 | /** |
||
| 245 | * Prepares a string to be outputed into a file. |
||
| 246 | * |
||
| 247 | * @param string $string The string to be converted. |
||
| 248 | * |
||
| 249 | * @return string |
||
| 250 | */ |
||
| 251 | protected function cleanExport($string) |
||
| 270 | |||
| 271 | /** |
||
| 272 | * @param string $value |
||
| 273 | * |
||
| 274 | * @return array |
||
| 275 | */ |
||
| 276 | private function wrapString($value) |
||
| 286 | } |
||
| 287 |