| Conditions | 10 |
| Paths | 48 |
| Total Lines | 50 |
| Code Lines | 35 |
| 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 |
||
| 103 | #[\Override] |
||
| 104 | public static function fromXML(DOMElement $xml): static |
||
| 105 | { |
||
| 106 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 107 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 108 | |||
| 109 | $Id = null; |
||
| 110 | if ($xml->hasAttributeNS(C::NS_SEC_UTIL, 'Id')) { |
||
| 111 | $Id = new XMLAttribute(C::NS_SEC_UTIL, 'wsu', 'Id', $xml->getAttributeNS(C::NS_SEC_UTIL, 'Id')); |
||
| 112 | } |
||
| 113 | |||
| 114 | $namespacedAttributes = self::getAttributesNSFromXML($xml); |
||
| 115 | foreach ($namespacedAttributes as $i => $attr) { |
||
| 116 | if ($attr->getNamespaceURI() === null) { |
||
| 117 | if ($attr->getAttrName() === 'Name') { |
||
| 118 | unset($namespacedAttributes[$i]); |
||
| 119 | break; |
||
| 120 | } |
||
| 121 | } elseif ($attr->getNamespaceURI() === C::NS_SEC_UTIL) { |
||
| 122 | if ($attr->getAttrName() === 'Id') { |
||
| 123 | unset($namespacedAttributes[$i]); |
||
| 124 | break; |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } |
||
| 128 | |||
| 129 | $operatorContent = $children = []; |
||
| 130 | for ($n = $xml->firstChild; $n !== null; $n = $n->nextSibling) { |
||
| 131 | if (!($n instanceof DOMElement)) { |
||
| 132 | continue; |
||
| 133 | } elseif ($n->namespaceURI !== self::NS) { |
||
| 134 | $children[] = new Chunk($n); |
||
| 135 | continue; |
||
| 136 | } |
||
| 137 | |||
| 138 | $operatorContent[] = match ($n->localName) { |
||
| 139 | 'All' => All::fromXML($n), |
||
| 140 | 'ExactlyOne' => ExactlyOne::fromXML($n), |
||
| 141 | 'Policy' => Policy::fromXML($n), |
||
| 142 | 'PolicyReference' => PolicyReference::fromXML($n), |
||
| 143 | default => null, |
||
| 144 | }; |
||
| 145 | } |
||
| 146 | |||
| 147 | return new static( |
||
| 148 | self::getOptionalAttribute($xml, 'Name', null), |
||
| 149 | $Id, |
||
| 150 | $operatorContent, |
||
| 151 | $children, |
||
| 152 | $namespacedAttributes, |
||
| 153 | ); |
||
| 180 |