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 |
||
8 | class PoCompiler |
||
9 | { |
||
10 | const TOKEN_OBSOLETE = '#~ '; |
||
11 | /** @var int */ |
||
12 | protected $wrappingColumn; |
||
13 | |||
14 | /** @var string */ |
||
15 | protected $lineEnding; |
||
16 | |||
17 | /** |
||
18 | * PoCompiler constructor. |
||
19 | * |
||
20 | * @param int $wrappingColumn |
||
21 | * @param string $lineEnding |
||
22 | */ |
||
23 | public function __construct($wrappingColumn = 80, $lineEnding = "\n") |
||
28 | |||
29 | /** |
||
30 | * Compiles entries into a string |
||
31 | * |
||
32 | * @param Catalog $catalog |
||
33 | * |
||
34 | * @return string |
||
35 | * @throws \Exception |
||
36 | * @todo Write obsolete messages at the end of the file. |
||
37 | */ |
||
38 | public function compile(Catalog $catalog) |
||
83 | |||
84 | /** |
||
85 | * @return string |
||
86 | */ |
||
87 | protected function eol() |
||
91 | |||
92 | /** |
||
93 | * @param $entry |
||
94 | * |
||
95 | * @return string |
||
96 | */ |
||
97 | protected function buildPreviousEntry(Entry $entry) |
||
106 | |||
107 | /** |
||
108 | * @param $entry |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | protected function buildTranslatorComment(Entry $entry) |
||
125 | |||
126 | protected function buildDeveloperComment(Entry $entry) |
||
139 | |||
140 | protected function buildReference(Entry $entry) |
||
154 | |||
155 | protected function buildFlags(Entry $entry) |
||
164 | |||
165 | protected function buildContext(Entry $entry) |
||
175 | |||
176 | protected function buildMsgId(Entry $entry) |
||
184 | |||
185 | protected function buildMsgStr(Entry $entry, Header $headers) |
||
209 | |||
210 | /** |
||
211 | * @param Entry $entry |
||
212 | * |
||
213 | * @return string |
||
214 | */ |
||
215 | protected function buildMsgIdPlural(Entry $entry) |
||
224 | |||
225 | protected function buildProperty($property, $value, $obsolete = false) |
||
242 | |||
243 | /** |
||
244 | * Prepares a string to be outputed into a file. |
||
245 | * |
||
246 | * @param string $string The string to be converted. |
||
247 | * |
||
248 | * @return string |
||
249 | */ |
||
250 | protected function cleanExport($string) |
||
269 | |||
270 | /** |
||
271 | * @param string $value |
||
272 | * |
||
273 | * @return array |
||
274 | */ |
||
275 | private function wrapString($value) |
||
285 | } |
||
286 |