Conditions | 11 |
Paths | 7 |
Total Lines | 51 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
103 | public static function fromXML(DOMElement $xml): static |
||
104 | { |
||
105 | Assert::same($xml->localName, 'AttributeValue', InvalidDOMElementException::class); |
||
106 | Assert::same($xml->namespaceURI, AttributeValue::NS, InvalidDOMElementException::class); |
||
107 | |||
108 | if ($xml->childElementCount > 0) { |
||
109 | $node = $xml->firstElementChild; |
||
110 | |||
111 | if (str_contains($node->tagName, ':')) { |
||
112 | list($prefix, $eltName) = explode(':', $node->tagName); |
||
113 | $className = sprintf('\SimpleSAML\SAML2\XML\%s\%s', $prefix, $eltName); |
||
114 | |||
115 | if (class_exists($className)) { |
||
116 | $value = $className::fromXML($node); |
||
117 | } else { |
||
118 | $value = Chunk::fromXML($node); |
||
|
|||
119 | } |
||
120 | } else { |
||
121 | $value = Chunk::fromXML($node); |
||
122 | } |
||
123 | } elseif ( |
||
124 | $xml->hasAttributeNS(C::NS_XSI, "type") && |
||
125 | $xml->getAttributeNS(C::NS_XSI, "type") === "xs:integer" |
||
126 | ) { |
||
127 | Assert::numeric($xml->textContent); |
||
128 | |||
129 | // we have an integer as value |
||
130 | $value = intval($xml->textContent); |
||
131 | } elseif ( |
||
132 | $xml->hasAttributeNS(C::NS_XSI, "type") && |
||
133 | $xml->getAttributeNS(C::NS_XSI, "type") === "xs:dateTime" |
||
134 | ) { |
||
135 | Assert::validDateTime($xml->textContent); |
||
136 | |||
137 | // we have a dateTime as value |
||
138 | $value = new DateTimeImmutable($xml->textContent); |
||
139 | } elseif ( |
||
140 | // null value |
||
141 | $xml->hasAttributeNS(C::NS_XSI, "nil") && |
||
142 | ($xml->getAttributeNS(C::NS_XSI, "nil") === "1" || |
||
143 | $xml->getAttributeNS(C::NS_XSI, "nil") === "true") |
||
144 | ) { |
||
145 | Assert::isEmpty($xml->nodeValue); |
||
146 | Assert::isEmpty($xml->textContent); |
||
147 | |||
148 | $value = null; |
||
149 | } else { |
||
150 | $value = $xml->textContent; |
||
151 | } |
||
152 | |||
153 | return new static($value); |
||
154 | } |
||
201 |