| Conditions | 19 |
| Paths | 84 |
| Total Lines | 74 |
| Code Lines | 29 |
| 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 |
||
| 160 | private static function registerSubtreePrefixes(DOMXPath $xp, DOMNode $node, array $prefixToUri): void |
||
| 161 | { |
||
| 162 | $root = $node instanceof DOMDocument |
||
| 163 | ? $node->documentElement |
||
| 164 | : ($node instanceof DOMElement ? $node : $node->parentNode); |
||
| 165 | |||
| 166 | if (!$root instanceof DOMElement) { |
||
| 167 | return; |
||
| 168 | } |
||
| 169 | |||
| 170 | // $visited = 0; |
||
| 171 | |||
| 172 | /** @var array<array{0:\DOMElement,1:int}> $queue */ |
||
| 173 | $queue = [[$root, 0]]; |
||
| 174 | |||
| 175 | while ($queue) { |
||
| 176 | /** @var \DOMElement $el */ |
||
| 177 | /** @var int $depth */ |
||
| 178 | [$el, $depth] = array_shift($queue); |
||
| 179 | |||
| 180 | // Depth guard: cap traversal at UNBOUNDED_LIMIT (root = depth 0). |
||
| 181 | // Breaking here halts further descent to avoid pathological depth and excessive work, |
||
| 182 | // which is safer in production than risking runaway traversal or hard failures. |
||
| 183 | // Trade-off: deeper descendant-only prefixes may remain unregistered, so some |
||
| 184 | // prefixed XPath queries might fail; overall processing continues gracefully. |
||
| 185 | if ($depth >= C_XML::UNBOUNDED_LIMIT) { |
||
| 186 | break; |
||
| 187 | } |
||
| 188 | |||
| 189 | // if (++$visited > C_XML::UNBOUNDED_LIMIT) { |
||
| 190 | // // Safety valve: stop further traversal to avoid unbounded work and noisy exceptions. |
||
| 191 | // // Returning here halts namespace registration for this subtree, which is safer in |
||
| 192 | // // production than risking pathological O(n) behavior or a hard failure (e.g. throwing |
||
| 193 | // // \RuntimeException(__METHOD__ . ': exceeded subtree traversal limit')). |
||
| 194 | // // Trade-off: some descendant-only prefixes may remain unregistered, so related XPath |
||
| 195 | // // queries might fail, but overall processing continues gracefully. |
||
| 196 | // break; |
||
| 197 | // } |
||
| 198 | |||
| 199 | // Element prefix |
||
| 200 | if ($el->prefix && !isset($prefixToUri[$el->prefix])) { |
||
| 201 | $uri = $el->namespaceURI; |
||
| 202 | if (is_string($uri) && $uri !== '') { |
||
| 203 | $xp->registerNamespace($el->prefix, $uri); |
||
| 204 | $prefixToUri[$el->prefix] = $uri; |
||
| 205 | } |
||
| 206 | } |
||
| 207 | |||
| 208 | // Attribute prefixes (excluding xmlns) |
||
| 209 | if ($el->hasAttributes()) { |
||
| 210 | foreach ($el->attributes as $attr) { |
||
| 211 | if ( |
||
| 212 | $attr->prefix && |
||
| 213 | $attr->prefix !== 'xmlns' && |
||
| 214 | !isset($prefixToUri[$attr->prefix]) |
||
| 215 | ) { |
||
| 216 | $uri = $attr->namespaceURI; |
||
| 217 | if (is_string($uri) && $uri !== '') { |
||
| 218 | $xp->registerNamespace($attr->prefix, $uri); |
||
| 219 | $prefixToUri[$attr->prefix] = $uri; |
||
| 220 | } |
||
| 221 | } else { |
||
| 222 | // Optional: collision detection (same prefix, different URI) |
||
| 223 | // if ($prefixToUri[$pfx] !== $attr->namespaceURI) { |
||
| 224 | // // Default: skip rebind; could log a debug message here. |
||
| 225 | // } |
||
| 226 | } |
||
| 227 | } |
||
| 228 | } |
||
| 229 | |||
| 230 | // Enqueue children (only DOMElement to keep types precise) |
||
| 231 | foreach ($el->childNodes as $child) { |
||
| 232 | if ($child instanceof DOMElement) { |
||
| 233 | $queue[] = [$child, $depth + 1]; |
||
| 234 | } |
||
| 262 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths