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