| Conditions | 10 |
| Paths | 14 |
| Total Lines | 29 |
| Code Lines | 19 |
| 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 |
||
| 68 | public static function fromXML(DOMElement $xml): static |
||
| 69 | { |
||
| 70 | Assert::same($xml->localName, static::getLocalName(), InvalidDOMElementException::class); |
||
| 71 | Assert::same($xml->namespaceURI, static::NS, InvalidDOMElementException::class); |
||
| 72 | |||
| 73 | $registry = ElementRegistry::getInstance(); |
||
| 74 | $tuples = []; |
||
| 75 | $tuple = [null, null]; |
||
| 76 | foreach ($xml->childNodes as $node) { |
||
| 77 | if ($node instanceof DOMElement) { |
||
| 78 | if ($node->namespaceURI === static::NS && $node->localName === 'SPKISexp') { |
||
| 79 | if ($tuple[0] !== null) { |
||
| 80 | $tuples[] = $tuple; |
||
| 81 | } |
||
| 82 | $tuple = [SPKISexp::fromXML($node), null]; |
||
| 83 | } elseif ($node->namespaceURI !== static::NS && $tuple[0] !== null) { |
||
| 84 | $handler = $registry->getElementHandler($node->namespaceURI, $node->localName); |
||
| 85 | $tuple[1] = ($handler === null) ? Chunk::fromXML($node) : $handler::fromXML($node); |
||
| 86 | $tuples[] = $tuple; |
||
| 87 | $tuple = [null, null]; |
||
| 88 | } |
||
| 89 | } |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($tuple[0] !== null) { |
||
| 93 | $tuples[] = $tuple; |
||
| 94 | } |
||
| 95 | |||
| 96 | return new static($tuples); |
||
| 97 | } |
||
| 118 |