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