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