| Conditions | 17 |
| Paths | 9 |
| Total Lines | 58 |
| Code Lines | 32 |
| 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 |
||
| 94 | protected static function getAttributesNSFromXML(DOMElement $xml, string|array $namespace = null): array |
||
| 95 | { |
||
| 96 | $namespace = $namespace ?? static::XS_ANY_ATTR_NAMESPACE; |
||
|
1 ignored issue
–
show
|
|||
| 97 | $attributes = []; |
||
| 98 | |||
| 99 | // Validate namespace value |
||
| 100 | if (!is_array($namespace)) { |
||
| 101 | // Must be one of the predefined values |
||
| 102 | Assert::oneOf($namespace, C::XS_ANY_NS); |
||
| 103 | |||
| 104 | if ($namespace === C::XS_ANY_NS_ANY) { |
||
| 105 | foreach ($xml->attributes as $a) { |
||
| 106 | $attributes[] = new Attribute($a->namespaceURI, $a->prefix, $a->localName, $a->nodeValue); |
||
| 107 | } |
||
| 108 | } elseif ($namespace === C::XS_ANY_NS_LOCAL) { |
||
| 109 | foreach ($xml->attributes as $a) { |
||
| 110 | if ($a->namespaceURI === null) { |
||
| 111 | $attributes[] = new Attribute($a->namespaceURI, $a->prefix, $a->localName, $a->nodeValue); |
||
| 112 | } |
||
| 113 | } |
||
| 114 | } elseif ($namespace === C::XS_ANY_NS_OTHER) { |
||
| 115 | foreach ($xml->attributes as $a) { |
||
| 116 | if ($a->namespaceURI !== static::NS) { |
||
|
1 ignored issue
–
show
|
|||
| 117 | $attributes[] = new Attribute($a->namespaceURI, $a->prefix, $a->localName, $a->nodeValue); |
||
| 118 | } |
||
| 119 | } |
||
| 120 | } elseif ($namespace === C::XS_ANY_NS_TARGET) { |
||
| 121 | foreach ($xml->attributes as $a) { |
||
| 122 | if ($a->namespaceURI === static::NS) { |
||
| 123 | $attributes[] = new Attribute($a->namespaceURI, $a->prefix, $a->localName, $a->nodeValue); |
||
| 124 | } |
||
| 125 | } |
||
| 126 | } |
||
| 127 | } else { |
||
| 128 | // Array must be non-empty and cannot contain ##any or ##other |
||
| 129 | Assert::notEmpty($namespace); |
||
| 130 | Assert::allStringNotEmpty($namespace); |
||
| 131 | Assert::allNotSame($namespace, C::XS_ANY_NS_ANY); |
||
| 132 | Assert::allNotSame($namespace, C::XS_ANY_NS_OTHER); |
||
| 133 | |||
| 134 | // Replace the ##targetedNamespace with the actual namespace |
||
| 135 | if (($key = array_search(C::XS_ANY_NS_TARGET, $namespace)) !== false) { |
||
| 136 | $namespace[$key] = static::NS; |
||
| 137 | } |
||
| 138 | |||
| 139 | // Replace the ##local with null |
||
| 140 | if (($key = array_search(C::XS_ANY_NS_LOCAL, $namespace)) !== false) { |
||
| 141 | $namespace[$key] = null; |
||
| 142 | } |
||
| 143 | |||
| 144 | foreach ($xml->attributes as $a) { |
||
| 145 | if (in_array($a->namespaceURI, $namespace, true)) { |
||
| 146 | $attributes[] = new Attribute($a->namespaceURI, $a->prefix, $a->localName, $a->nodeValue); |
||
| 147 | } |
||
| 148 | } |
||
| 149 | } |
||
| 150 | |||
| 151 | return $attributes; |
||
| 152 | } |
||
| 252 |