| Conditions | 17 |
| Paths | 97 |
| Total Lines | 170 |
| Code Lines | 88 |
| 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 |
||
| 262 | public function customXPath($xPath, $newGroupFlag = false, $value = '', $attributeOnly = false) |
||
| 263 | { |
||
| 264 | if (!$attributeOnly) { |
||
| 265 | // Explode xPath |
||
| 266 | $newPath = explode('%', $xPath); |
||
| 267 | |||
| 268 | $praedicateFlag = false; |
||
| 269 | $explodedXPath = explode('[', $newPath[0]); |
||
| 270 | if (count($explodedXPath) > 1) { |
||
| 271 | // praedicate is given |
||
| 272 | if (substr($explodedXPath[1], 0, 1) == "@") { |
||
| 273 | // attribute |
||
| 274 | $path = $newPath[0]; |
||
| 275 | } else { |
||
| 276 | // path |
||
| 277 | $path = $explodedXPath[0]; |
||
| 278 | } |
||
| 279 | |||
| 280 | $praedicateFlag = true; |
||
| 281 | } else { |
||
| 282 | $path = $newPath[0]; |
||
| 283 | } |
||
| 284 | |||
| 285 | if (!empty($value)) { |
||
| 286 | $newPath[1] = $newPath[1] . '="' . $value . '"'; |
||
| 287 | } |
||
| 288 | |||
| 289 | $modsDataXPath = \EWW\Dpf\Helper\XPath::create($this->xmlData); |
||
| 290 | |||
| 291 | if (!$newGroupFlag && $modsDataXPath->query('/data/' . $newPath[0])->length > 0) { |
||
| 292 | // first xpath path exist |
||
| 293 | |||
| 294 | // build xml from second xpath part |
||
| 295 | $xml = $this->parseXPath($newPath[1]); |
||
| 296 | |||
| 297 | // check if xpath [] are nested |
||
| 298 | $search = '/(\/\w*:\w*)\[(.*)\]/'; |
||
| 299 | preg_match($search, $newPath[1], $match); |
||
| 300 | preg_match($search, $match[2], $secondMatch); |
||
| 301 | // first part nested xpath |
||
| 302 | if ($match[2] && $secondMatch[2]) { |
||
| 303 | $nested = $match[2]; |
||
| 304 | |||
| 305 | $nestedXml = $this->parseXPath($nested); |
||
| 306 | |||
| 307 | // object xpath without nested element [] |
||
| 308 | $newPath[1] = str_replace('['.$match[2].']', '', $newPath[1]); |
||
| 309 | |||
| 310 | $xml = $this->parseXPath($newPath[1]); |
||
| 311 | |||
| 312 | } |
||
| 313 | |||
| 314 | $docXML = new \DOMDocument(); |
||
| 315 | $docXML->loadXML($xml); |
||
| 316 | |||
| 317 | $domXPath = \EWW\Dpf\Helper\XPath::create($this->xmlData); |
||
| 318 | |||
| 319 | // second part nested xpath |
||
| 320 | if ($match[2] && $secondMatch[2]) { |
||
| 321 | // import node from nested |
||
| 322 | $docXMLNested = new \DOMDocument(); |
||
| 323 | $docXMLNested->loadXML($nestedXml); |
||
| 324 | |||
| 325 | $xPath = \EWW\Dpf\Helper\XPath::create($docXML); |
||
| 326 | |||
| 327 | $nodeList = $xPath->query($match[1]); |
||
| 328 | $node = $nodeList->item(0); |
||
| 329 | |||
| 330 | $importNode = $docXML->importNode($docXMLNested->getElementsByTagName("mods")->item(0)->firstChild, true); |
||
| 331 | |||
| 332 | $node->appendChild($importNode); |
||
| 333 | } |
||
| 334 | |||
| 335 | $domNode = $domXPath->query('/data/' . $path); |
||
| 336 | $node = $docXML->documentElement; |
||
| 337 | |||
| 338 | $nodeAppendModsData = $this->xmlData->importNode($node, true); |
||
| 339 | $domNode->item($domNode->length - 1)->appendChild($nodeAppendModsData); |
||
| 340 | } else { |
||
| 341 | // first xpath doesn't exist |
||
| 342 | // parse first xpath part |
||
| 343 | $xml1 = $this->parseXPathWrapped($newPath[0]); |
||
| 344 | |||
| 345 | $doc1 = new \DOMDocument(); |
||
| 346 | $doc1->loadXML($xml1); |
||
| 347 | |||
| 348 | $domXPath = \EWW\Dpf\Helper\XPath::create($doc1); |
||
| 349 | |||
| 350 | $domNode = $domXPath->query('//' . $path); |
||
| 351 | |||
| 352 | // parse second xpath part |
||
| 353 | $xml2 = $this->parseXPathWrapped($path . $newPath[1]); |
||
| 354 | |||
| 355 | // check if xpath [] are nested |
||
| 356 | $search = '/(\/\w*:?\w*)\[(.*)\]/'; |
||
| 357 | preg_match($search, $newPath[1], $match); |
||
| 358 | preg_match($search, $match[2], $secondMatch); |
||
| 359 | |||
| 360 | // first part nested xpath |
||
| 361 | if ($match[2] && $secondMatch[2]) { |
||
| 362 | $nested = $match[2]; |
||
| 363 | |||
| 364 | $nestedXml = $this->parseXPathWrapped($nested); |
||
| 365 | |||
| 366 | // object xpath without nested element [] |
||
| 367 | $newPath[1] = str_replace('['.$match[2].']', '', $newPath[1]); |
||
| 368 | |||
| 369 | $xml2 = $this->parseXPathWrapped($path . $newPath[1]); |
||
| 370 | } |
||
| 371 | |||
| 372 | $doc2 = new \DOMDocument(); |
||
| 373 | $doc2->loadXML($xml2); |
||
| 374 | |||
| 375 | $domXPath2 = \EWW\Dpf\Helper\XPath::create($doc2); |
||
| 376 | |||
| 377 | // second part nested xpath |
||
| 378 | if ($match[2] && $secondMatch[2]) { |
||
| 379 | // import node from nested |
||
| 380 | $docXMLNested = new \DOMDocument(); |
||
| 381 | $docXMLNested->loadXML($nestedXml); |
||
| 382 | |||
| 383 | $xPath = \EWW\Dpf\Helper\XPath::create($doc2); |
||
| 384 | $nodeList = $xPath->query('//' . $path . $match[1]); |
||
| 385 | $node = $nodeList->item(0); |
||
| 386 | |||
| 387 | $importNode = $doc2->importNode($docXMLNested->documentElement, true); |
||
| 388 | |||
| 389 | $node->appendChild($importNode); |
||
| 390 | } |
||
| 391 | $domNode2 = $domXPath2->query('//' . $path)->item(0)->childNodes->item(0); |
||
| 392 | |||
| 393 | // merge xml nodes |
||
| 394 | $nodeToBeAppended = $doc1->importNode($domNode2, true); |
||
| 395 | $domNode->item(0)->appendChild($nodeToBeAppended); |
||
| 396 | |||
| 397 | // add to modsData (merge not required) |
||
| 398 | // get mods tag |
||
| 399 | foreach ($this->xmlData->childNodes as $childNode) { |
||
| 400 | // Skip comments inside the xml. |
||
| 401 | if ($childNode instanceof \DOMElement) { |
||
| 402 | $firstChild = $childNode; |
||
| 403 | break; |
||
| 404 | } |
||
| 405 | } |
||
| 406 | //$firstChild = $this->xmlData->childNodes->item(0); |
||
| 407 | $firstItem = $doc1->documentElement->firstChild; |
||
| 408 | $nodeAppendModsData = $this->xmlData->importNode($firstItem, true); |
||
| 409 | $firstChild->appendChild($nodeAppendModsData); |
||
| 410 | |||
| 411 | return $doc1->saveXML(); |
||
| 412 | } |
||
| 413 | } else { |
||
| 414 | // attribute only |
||
| 415 | $xml = $this->parseXPath($xPath); |
||
| 416 | |||
| 417 | $docXML = new \DOMDocument(); |
||
| 418 | $docXML->loadXML($xml); |
||
| 419 | |||
| 420 | $domXPath = \EWW\Dpf\Helper\XPath::create($this->xmlData); |
||
| 421 | $domNode = $domXPath->query('/data'); |
||
| 422 | |||
| 423 | $node = $docXML->documentElement; |
||
| 424 | |||
| 425 | $nodeAppendModsData = $this->xmlData->importNode($node, true); |
||
| 426 | $domNode->item($domNode->length - 1)->appendChild($nodeAppendModsData); |
||
| 427 | |||
| 428 | return $docXML->saveXML(); |
||
| 429 | } |
||
| 430 | |||
| 431 | return $this->xmlData->saveXML(); |
||
| 432 | } |
||
| 476 |
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