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 |
||
7 | class PoCompiler |
||
8 | { |
||
9 | const TOKEN_OBSOLETE = '#~ '; |
||
10 | /** @var int */ |
||
11 | protected $wrappingColumn; |
||
12 | |||
13 | /** @var string */ |
||
14 | protected $lineEnding; |
||
15 | |||
16 | /** |
||
17 | * PoCompiler constructor. |
||
18 | * |
||
19 | * @param int $wrappingColumn |
||
20 | * @param string $lineEnding |
||
21 | */ |
||
22 | public function __construct($wrappingColumn = 80, $lineEnding = "\n") |
||
27 | |||
28 | /** |
||
29 | * Compiles entries into a string |
||
30 | * |
||
31 | * @param Catalog $catalog |
||
32 | * |
||
33 | * @return string |
||
34 | * @throws \Exception |
||
35 | * @todo Write obsolete messages at the end of the file. |
||
36 | */ |
||
37 | public function compile(Catalog $catalog) |
||
82 | |||
83 | /** |
||
84 | * @return string |
||
85 | */ |
||
86 | protected function eol() |
||
90 | |||
91 | /** |
||
92 | * @param $entry |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | protected function buildPreviousEntry(Entry $entry) |
||
119 | |||
120 | /** |
||
121 | * @param $entry |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | protected function buildTranslatorComment(Entry $entry) |
||
138 | |||
139 | protected function buildDeveloperComment(Entry $entry) |
||
152 | |||
153 | protected function buildReference(Entry $entry) |
||
167 | |||
168 | protected function buildFlags(Entry $entry) |
||
177 | |||
178 | protected function buildContext(Entry $entry) |
||
188 | |||
189 | protected function buildMsgId(Entry $entry) |
||
197 | |||
198 | protected function buildMsgStr(Entry $entry) |
||
218 | |||
219 | /** |
||
220 | * @param Entry $entry |
||
221 | * |
||
222 | * @return string |
||
223 | */ |
||
224 | protected function buildMsgIdPlural(Entry $entry) |
||
233 | |||
234 | protected function buildProperty($property, $value, $obsolete = false) |
||
251 | |||
252 | /** |
||
253 | * Prepares a string to be outputed into a file. |
||
254 | * |
||
255 | * @param string $string The string to be converted. |
||
256 | * |
||
257 | * @return string |
||
258 | */ |
||
259 | protected function cleanExport($string) |
||
278 | |||
279 | /** |
||
280 | * @param string $value |
||
281 | * |
||
282 | * @return array |
||
283 | */ |
||
284 | private function wrapString($value) |
||
294 | } |
||
295 |