Conditions | 11 |
Paths | 7 |
Total Lines | 43 |
Code Lines | 28 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
93 | public static function fromXML(DOMElement $xml): static |
||
94 | { |
||
95 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
96 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
97 | |||
98 | if ($xml->childElementCount > 0) { |
||
99 | $node = $xml->firstElementChild; |
||
100 | |||
101 | if (str_contains($node->tagName, ':')) { |
||
102 | list($prefix, $eltName) = explode(':', $node->tagName); |
||
103 | $className = sprintf('\SimpleSAML\SAML11\XML\%s\%s', $prefix, $eltName); |
||
104 | |||
105 | if (class_exists($className)) { |
||
106 | $value = $className::fromXML($node); |
||
107 | } else { |
||
108 | $value = Chunk::fromXML($node); |
||
109 | } |
||
110 | } else { |
||
111 | $value = Chunk::fromXML($node); |
||
112 | } |
||
113 | } elseif ( |
||
114 | $xml->hasAttributeNS(C::NS_XSI, "type") && |
||
115 | $xml->getAttributeNS(C::NS_XSI, "type") === "xs:integer" |
||
116 | ) { |
||
117 | // we have an integer as value |
||
118 | $value = IntegerValue::fromString($xml->textContent); |
||
119 | } elseif ( |
||
120 | $xml->hasAttributeNS(C::NS_XSI, "nil") && |
||
121 | ($xml->getAttributeNS(C::NS_XSI, "nil") === "1" || $xml->getAttributeNS(C::NS_XSI, "nil") === "true") |
||
122 | ) { |
||
123 | // we have a nill value |
||
124 | $value = null; |
||
125 | } elseif ( |
||
126 | $xml->hasAttributeNS(C::NS_XSI, "type") && |
||
127 | $xml->getAttributeNS(C::NS_XSI, "type") === "xs:dateTime" |
||
128 | ) { |
||
129 | // we have a dateTime as value |
||
130 | $value = DateTimeValue::fromString($xml->textContent); |
||
131 | } else { |
||
132 | $value = StringValue::fromString($xml->textContent); |
||
133 | } |
||
134 | |||
135 | return new static($value); |
||
136 | } |
||
186 |