Complex classes like AbstractSamlModel 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 AbstractSamlModel, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
18 | abstract class AbstractSamlModel implements SamlElementInterface |
||
19 | { |
||
20 | /** |
||
21 | * @param string $name |
||
22 | * @param null|string $namespace |
||
23 | * @param \DOMNode $parent |
||
24 | * @param SerializationContext $context |
||
25 | * |
||
26 | * @return \DOMElement |
||
27 | */ |
||
28 | 27 | protected function createElement($name, $namespace, \DOMNode $parent, SerializationContext $context) |
|
39 | |||
40 | /** |
||
41 | * @param string $name |
||
42 | * @param \DOMNode $parent |
||
43 | * @param SerializationContext $context |
||
44 | * @param string|null $namespace |
||
45 | * |
||
46 | * @throws \LogicException |
||
47 | */ |
||
48 | 27 | private function oneElementToXml($name, \DOMNode $parent, SerializationContext $context, $namespace = null) |
|
67 | |||
68 | /** |
||
69 | * @param array|string[] $names |
||
70 | * @param \DOMNode $parent |
||
71 | * @param SerializationContext $context |
||
72 | * @param string|null $namespace |
||
73 | */ |
||
74 | 27 | protected function singleElementsToXml(array $names, \DOMNode $parent, SerializationContext $context, $namespace = null) |
|
80 | |||
81 | /** |
||
82 | * @param array|null $value |
||
83 | * @param \DOMNode $node |
||
84 | * @param SerializationContext $context |
||
85 | * @param null|string $nodeName |
||
86 | * @param null|string $namespaceUri |
||
87 | * |
||
88 | * @throws \LogicException |
||
89 | */ |
||
90 | 13 | protected function manyElementsToXml($value, \DOMNode $node, SerializationContext $context, $nodeName = null, $namespaceUri = null) |
|
118 | |||
119 | /** |
||
120 | * @param \DOMElement $node |
||
121 | * @param DeserializationContext $context |
||
122 | * @param string $nodeName |
||
123 | * @param string|null $namespacePrefix |
||
124 | * @param string $class |
||
125 | * @param string $methodName |
||
126 | * |
||
127 | * @throws \LogicException |
||
128 | */ |
||
129 | 47 | protected function manyElementsFromXml(\DOMElement $node, DeserializationContext $context, $nodeName, $namespacePrefix, $class, $methodName) |
|
153 | |||
154 | /** |
||
155 | * @param string $name |
||
156 | * @param \DOMElement $element |
||
157 | * |
||
158 | * @throws \LogicException |
||
159 | * |
||
160 | * @return bool True if property value is not empty and attribute was set to the element |
||
161 | */ |
||
162 | 27 | protected function singleAttributeToXml($name, \DOMElement $element) |
|
177 | |||
178 | /** |
||
179 | * @param array|string[] $names |
||
180 | * @param \DOMElement $element |
||
181 | */ |
||
182 | 27 | protected function attributesToXml(array $names, \DOMElement $element) |
|
188 | |||
189 | /** |
||
190 | * @param \DOMNode $node |
||
191 | * @param string $expectedName |
||
192 | * @param string $expectedNamespaceUri |
||
193 | */ |
||
194 | 64 | protected function checkXmlNodeName(\DOMNode &$node, $expectedName, $expectedNamespaceUri) |
|
218 | |||
219 | /** |
||
220 | * @param \DOMElement $node |
||
221 | * @param string $attributeName |
||
222 | */ |
||
223 | 62 | protected function singleAttributeFromXml(\DOMElement $node, $attributeName) |
|
233 | |||
234 | /** |
||
235 | * @param \DOMElement $node |
||
236 | * @param DeserializationContext $context |
||
237 | * @param string $elementName |
||
238 | * @param string $class |
||
239 | * @param string $namespacePrefix |
||
240 | * |
||
241 | * @throws \LogicException |
||
242 | */ |
||
243 | 62 | protected function oneElementFromXml(\DOMElement $node, DeserializationContext $context, $elementName, $class, $namespacePrefix) |
|
282 | |||
283 | /** |
||
284 | * @param \DOMElement $node |
||
285 | * @param DeserializationContext $context |
||
286 | * @param array $options elementName=>class |
||
287 | */ |
||
288 | 62 | protected function singleElementsFromXml(\DOMElement $node, DeserializationContext $context, array $options) |
|
294 | |||
295 | /** |
||
296 | * @param \DOMElement $node |
||
297 | * @param array $attributeNames |
||
298 | */ |
||
299 | 62 | protected function attributesFromXml(\DOMElement $node, array $attributeNames) |
|
305 | |||
306 | /** |
||
307 | * @param string $name |
||
308 | * |
||
309 | * @return mixed |
||
310 | * |
||
311 | * @throws \LogicException |
||
312 | */ |
||
313 | 27 | private function getPropertyValue($name) |
|
333 | } |
||
334 |
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: