Complex classes like Xsl 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 Xsl, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
31 | class Xsl extends WriterAbstract implements Routable |
||
|
|||
32 | { |
||
33 | /** @var \Monolog\Logger $logger */ |
||
34 | protected $logger; |
||
35 | |||
36 | /** @var string[] */ |
||
37 | protected $xsl_variables = array(); |
||
38 | |||
39 | /** @var Queue */ |
||
40 | private $routers; |
||
41 | |||
42 | /** |
||
43 | * Initialize this writer with the logger so that it can output logs. |
||
44 | * |
||
45 | * @param Logger $logger |
||
46 | */ |
||
47 | public function __construct(Logger $logger) |
||
51 | |||
52 | /** |
||
53 | * Checks whether XSL handling is enabled with PHP as that is not enabled by default. |
||
54 | * |
||
55 | * To enable XSL handling you need either the xsl extension or the xslcache extension installed. |
||
56 | * |
||
57 | * @throws RequirementMissing if neither xsl extensions are installed. |
||
58 | * |
||
59 | * @return void |
||
60 | */ |
||
61 | public function checkRequirements() |
||
70 | |||
71 | /** |
||
72 | * Sets the routers that can be used to determine the path of links. |
||
73 | * |
||
74 | * @param Queue $routers |
||
75 | * |
||
76 | * @return void |
||
77 | */ |
||
78 | public function setRouters(Queue $routers) |
||
82 | |||
83 | /** |
||
84 | * This method combines the structure.xml and the given target template |
||
85 | * and creates a static html page at the artifact location. |
||
86 | * |
||
87 | * @param ProjectDescriptor $project Document containing the structure. |
||
88 | * @param Transformation $transformation Transformation to execute. |
||
89 | * |
||
90 | * @throws \RuntimeException if the structure.xml file could not be found. |
||
91 | * @throws Exception if the structure.xml file's documentRoot could not be read because of encoding issues |
||
92 | * or because it was absent. |
||
93 | * |
||
94 | * @return void |
||
95 | */ |
||
96 | public function transform(ProjectDescriptor $project, Transformation $transformation) |
||
159 | |||
160 | /** |
||
161 | * Takes the filename and converts it into a correct URI for XSLTProcessor. |
||
162 | * |
||
163 | * @param string $filename |
||
164 | * |
||
165 | * @return string |
||
166 | */ |
||
167 | protected function getXsltUriFromFilename($filename) |
||
179 | |||
180 | /** |
||
181 | * Sets the parameters of the XSLT processor. |
||
182 | * |
||
183 | * @param TransformationObject $transformation Transformation. |
||
184 | * @param \XSLTProcessor $proc XSLTProcessor. |
||
185 | * |
||
186 | * @return void |
||
187 | */ |
||
188 | public function setProcessorParameters(TransformationObject $transformation, $proc) |
||
216 | |||
217 | /** |
||
218 | * |
||
219 | * |
||
220 | * @param Transformation $transformation |
||
221 | * |
||
222 | * @return \XSLTCache|\XSLTProcessor |
||
223 | */ |
||
224 | protected function getXslProcessor(Transformation $transformation) |
||
247 | |||
248 | /** |
||
249 | * @param $structureFilename |
||
250 | * @return \DOMDocument |
||
251 | */ |
||
252 | private function loadAst($structureFilename) |
||
277 | |||
278 | /** |
||
279 | * @param Transformation $transformation |
||
280 | * @param $proc |
||
281 | * @param $structure |
||
282 | */ |
||
283 | private function registerDefaultVariables(Transformation $transformation, $proc, $structure) |
||
296 | |||
297 | /** |
||
298 | * @param $filename |
||
299 | * @param $proc |
||
300 | * @param $structure |
||
301 | */ |
||
302 | private function writeToFile($filename, $proc, $structure) |
||
309 | |||
310 | /** |
||
311 | * @param Transformation $transformation |
||
312 | * @return string |
||
313 | */ |
||
314 | private function getAstPath(Transformation $transformation) |
||
318 | |||
319 | /** |
||
320 | * Returns the path to the location where the artifact should be written, or null to automatically detect the |
||
321 | * location using the router. |
||
322 | * |
||
323 | * @param Transformation $transformation |
||
324 | * |
||
325 | * @return string|null |
||
326 | */ |
||
327 | private function getArtifactPath(Transformation $transformation) |
||
333 | |||
334 | /** |
||
335 | * @param ProjectDescriptor $project |
||
336 | * @param $element |
||
337 | * @return false|string |
||
338 | */ |
||
339 | private function generateUrlForXmlElement(ProjectDescriptor $project, $element) |
||
361 | } |
||
362 |