Complex classes like Version2 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 Version2, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
26 | final class Version2 implements Strategy |
||
27 | { |
||
28 | /** @var string[] */ |
||
29 | private $extensions = ['php', 'php3', 'phtml']; |
||
30 | |||
31 | /** @var string[] */ |
||
32 | private $markers = ['TODO', 'FIXME']; |
||
33 | |||
34 | /** @var string[] */ |
||
35 | private $visibility = ['public', 'protected', 'private']; |
||
36 | |||
37 | /** @var string */ |
||
38 | private $defaultPackageName = 'Default'; |
||
39 | |||
40 | /** @var string */ |
||
41 | private $template = 'clean'; |
||
42 | |||
43 | /** @var bool */ |
||
44 | private $ignoreHidden = true; |
||
45 | |||
46 | /** @var bool */ |
||
47 | private $ignoreSymlinks = true; |
||
48 | |||
49 | /** @var string[] */ |
||
50 | private $ignorePaths = []; |
||
51 | |||
52 | /** @var string */ |
||
53 | private $outputDirectory = 'file://build/docs'; |
||
54 | |||
55 | /** @var string[] */ |
||
56 | private $directories = ['src']; |
||
57 | |||
58 | private $includeSource = false; |
||
59 | |||
60 | 6 | public function convert(SimpleXMLElement $phpDocumentor): array |
|
110 | |||
111 | 1 | public function supports(SimpleXMLElement $phpDocumentor): bool |
|
116 | |||
117 | /** |
||
118 | * Loops over a node and fills an array with the found children. |
||
119 | */ |
||
120 | 1 | private function buildArrayFromNode(SimpleXMLElement $node): array |
|
131 | |||
132 | /** |
||
133 | * Builds the extensions part of the array from the configuration xml. |
||
134 | * |
||
135 | * @return string[] |
||
136 | */ |
||
137 | 6 | private function buildExtensions(SimpleXMLElement $phpDocumentor): array |
|
149 | |||
150 | /** |
||
151 | * Builds the markers part of the array from the configuration xml. |
||
152 | * |
||
153 | * @return string[] |
||
154 | */ |
||
155 | 6 | private function buildMarkers(SimpleXMLElement $phpDocumentor): array |
|
167 | |||
168 | /** |
||
169 | * Builds whether the source code should be part of the output. |
||
170 | */ |
||
171 | 6 | private function buildIncludeSourcecode(SimpleXMLElement $phpDocumentor): bool |
|
179 | |||
180 | /** |
||
181 | * Builds the visibility part of the array from the configuration xml. |
||
182 | * |
||
183 | * @return string[] |
||
184 | */ |
||
185 | 6 | private function buildVisibility(SimpleXMLElement $phpDocumentor): array |
|
197 | |||
198 | /** |
||
199 | * Builds the defaultPackageName part of the array from the configuration xml. |
||
200 | */ |
||
201 | 6 | private function buildDefaultPackageName(SimpleXMLElement $phpDocumentor): string |
|
213 | |||
214 | /** |
||
215 | * Builds the template part of the array from the configuration xml. |
||
216 | */ |
||
217 | 6 | private function buildTemplate(SimpleXMLElement $phpDocumentor): string |
|
229 | |||
230 | /** |
||
231 | * Builds the ignore-hidden part of the array from the configuration xml. |
||
232 | */ |
||
233 | 6 | private function buildIgnoreHidden(SimpleXMLElement $phpDocumentor): bool |
|
245 | |||
246 | /** |
||
247 | * Builds the ignore-symlinks part of the array from the configuration xml. |
||
248 | */ |
||
249 | 6 | private function buildIgnoreSymlinks(SimpleXMLElement $phpDocumentor): bool |
|
261 | |||
262 | /** |
||
263 | * Builds the ignorePaths part of the array from the configuration xml. |
||
264 | * |
||
265 | * @return string[] |
||
266 | */ |
||
267 | 6 | private function buildIgnorePaths(SimpleXMLElement $phpDocumentor): array |
|
285 | |||
286 | /** |
||
287 | * Builds the outputDirectory part of the array from the configuration xml. |
||
288 | */ |
||
289 | 6 | private function buildOutputDirectory(SimpleXMLElement $phpDocumentor): string |
|
301 | |||
302 | /** |
||
303 | * Builds the directories that are used in the sourcePaths. |
||
304 | * |
||
305 | * @return string[] |
||
306 | */ |
||
307 | 6 | private function buildDirectories(SimpleXMLElement $phpDocumentor): array |
|
319 | |||
320 | /** |
||
321 | * Builds the sourcePaths part of the array from the configuration xml. |
||
322 | * |
||
323 | * @return Path[] |
||
324 | */ |
||
325 | 6 | private function buildSourcePaths(SimpleXMLElement $phpDocumentor): array |
|
336 | |||
337 | /** |
||
338 | * Builds the outputDirectory part of the array from the configuration xml. |
||
339 | */ |
||
340 | 6 | private function buildCacheDirectory(SimpleXMLElement $phpDocumentor): string |
|
352 | |||
353 | /** |
||
354 | * Validates if the xml has a root element which name is phpdocumentor. |
||
355 | * |
||
356 | * @throws InvalidArgumentException if the root element of the xml is not phpdocumentor. |
||
357 | */ |
||
358 | 7 | private function validate(SimpleXMLElement $xml): void |
|
366 | |||
367 | 6 | private function buildEncoding(SimpleXMLElement $phpDocumentor) |
|
379 | } |
||
380 |