| Conditions | 19 |
| Paths | 16 |
| Total Lines | 62 |
| Code Lines | 38 |
| 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 |
||
| 44 | protected static function getChildElementsFromXML( |
||
| 45 | DOMElement $xml, |
||
| 46 | string|array|null $namespace = null, |
||
| 47 | ): array { |
||
| 48 | $namespace = $namespace ?? self::XS_ANY_ELT_NAMESPACE; |
||
| 49 | $exclusionList = self::getElementExclusions(); |
||
| 50 | $registry = ElementRegistry::getInstance(); |
||
| 51 | $elements = []; |
||
| 52 | |||
| 53 | // Validate namespace value |
||
| 54 | if (!is_array($namespace)) { |
||
| 55 | // Must be one of the predefined values |
||
| 56 | Assert::oneOf($namespace, NS::$PREDEFINED); |
||
| 57 | |||
| 58 | foreach ($xml->childNodes as $elt) { |
||
| 59 | if (!($elt instanceof DOMElement)) { |
||
| 60 | continue; |
||
| 61 | } elseif (in_array([$elt->namespaceURI, $elt->localName], $exclusionList, true)) { |
||
| 62 | continue; |
||
| 63 | } elseif ($namespace === NS::OTHER && in_array($elt->namespaceURI, [self::NS, null], true)) { |
||
|
|
|||
| 64 | continue; |
||
| 65 | } elseif ($namespace === NS::TARGETNAMESPACE && $elt->namespaceURI !== self::NS) { |
||
| 66 | continue; |
||
| 67 | } elseif ($namespace === NS::LOCAL && $elt->namespaceURI !== null) { |
||
| 68 | continue; |
||
| 69 | } |
||
| 70 | |||
| 71 | $handler = $registry->getElementHandler($elt->namespaceURI, $elt->localName); |
||
| 72 | $elements[] = ($handler === null) ? Chunk::fromXML($elt) : $handler::fromXML($elt); |
||
| 73 | } |
||
| 74 | } else { |
||
| 75 | // Array must be non-empty and cannot contain ##any or ##other |
||
| 76 | Assert::notEmpty($namespace); |
||
| 77 | Assert::allStringNotEmpty($namespace); |
||
| 78 | Assert::allNotSame($namespace, NS::ANY); |
||
| 79 | Assert::allNotSame($namespace, NS::OTHER); |
||
| 80 | |||
| 81 | // Replace the ##targetedNamespace with the actual namespace |
||
| 82 | if (($key = array_search(NS::TARGETNAMESPACE, $namespace)) !== false) { |
||
| 83 | $namespace[$key] = self::NS; |
||
| 84 | } |
||
| 85 | |||
| 86 | // Replace the ##local with null |
||
| 87 | if (($key = array_search(NS::LOCAL, $namespace)) !== false) { |
||
| 88 | $namespace[$key] = null; |
||
| 89 | } |
||
| 90 | |||
| 91 | foreach ($xml->childNodes as $elt) { |
||
| 92 | if (!($elt instanceof DOMElement)) { |
||
| 93 | continue; |
||
| 94 | } elseif (in_array([$elt->namespaceURI, $elt->localName], $exclusionList, true)) { |
||
| 95 | continue; |
||
| 96 | } elseif (!in_array($elt->namespaceURI, $namespace, true)) { |
||
| 97 | continue; |
||
| 98 | } |
||
| 99 | |||
| 100 | $handler = $registry->getElementHandler($elt->namespaceURI, $elt->localName); |
||
| 101 | $elements[] = ($handler === null) ? Chunk::fromXML($elt) : $handler::fromXML($elt); |
||
| 102 | } |
||
| 103 | } |
||
| 104 | |||
| 105 | return $elements; |
||
| 106 | } |
||
| 233 |