| @@ -22,14 +22,14 @@ discard block | ||
| 22 | 22 | * $xml can either be an XML string, a DOMDocument, or a DOMElement. | 
| 23 | 23 | * You can also pass FALSE or NULL (or omit it) and load XML later using loadXML or loadHTML | 
| 24 | 24 | * | 
| 25 | - * @param mixed $auto_register_namespaces | |
| 25 | + * @param boolean $auto_register_namespaces | |
| 26 | 26 | * Auto-register namespaces. All namespaces in the root element will be registered for use in xpath queries. | 
| 27 | 27 | * Namespaces that are not declared in the root element will not be auto-registered | 
| 28 | 28 | * Defaults to TRUE (Meaning it will auto register all auxiliary namespaces but not the default namespace). | 
| 29 | 29 | * Pass a prefix string to automatically register the default namespace. | 
| 30 | 30 | * Pass FALSE to disable auto-namespace registeration | 
| 31 | 31 | * | 
| 32 | - * @param bool $error_checking | |
| 32 | + * @param string|boolean $error_checking | |
| 33 | 33 | * Can be 'strict', 'warning', or 'none. Defaults to 'strict'. | 
| 34 | 34 | * 'none' supresses all errors | 
| 35 | 35 | * 'warning' is the default behavior in DOMDocument | 
| @@ -489,10 +489,10 @@ discard block | ||
| 489 | 489 | /** | 
| 490 | 490 | * Given a pair of nodes, replace the first with the second | 
| 491 | 491 | * | 
| 492 | - * @param mixed $node | |
| 492 | + * @param \DOMElement $node | |
| 493 | 493 | * Node to be replaced. Can either be an xpath string or a DOMDocument (or even a DOMNode). | 
| 494 | 494 | * | 
| 495 | - * @param mixed $replace | |
| 495 | + * @param \DOMElement $replace | |
| 496 | 496 | * Replace $node with $replace. Replace can be an XML string, or a DOMNode | 
| 497 | 497 | * | 
| 498 | 498 | * @return mixed | 
| @@ -552,7 +552,7 @@ discard block | ||
| 552 | 552 | * $context can either be an xpath string, or a DOMElement. Ommiting it | 
| 553 | 553 | * results in transforming the entire document | 
| 554 | 554 | * | 
| 555 | - * @return a new DOMDoc | |
| 555 | + * @return DOMDoc new DOMDoc | |
| 556 | 556 | */ | 
| 557 | 557 |    public function tranform($xsl, $context = NULL) { | 
| 558 | 558 |      if (!$context) { | 
| @@ -636,7 +636,7 @@ discard block | ||
| 636 | 636 | * it will transform all elements with xlink:type = simple into a <a href> element. | 
| 637 | 637 | * Alternatively you may specify your own xpath for selecting which elements get transformed | 
| 638 | 638 | * into <a href> tags. | 
| 639 | - * @return HTML string | |
| 639 | + * @return string string | |
| 640 | 640 | */ | 
| 641 | 641 |    public function asHTML($context = NULL, $options = array()) { | 
| 642 | 642 | $xslSimple = ' | 
| @@ -718,7 +718,7 @@ discard block | ||
| 718 | 718 | * $context can either be an xpath string, or a DOMElement. Ommiting it | 
| 719 | 719 | * results in outputting the entire document | 
| 720 | 720 | * | 
| 721 | - * @return XML string | |
| 721 | + * @return string string | |
| 722 | 722 | */ | 
| 723 | 723 |    public function out($context = NULL) { | 
| 724 | 724 | $this->createContext($context, 'xpath'); | 
| @@ -753,6 +753,9 @@ discard block | ||
| 753 | 753 | return $this->out(); | 
| 754 | 754 | } | 
| 755 | 755 | |
| 756 | + /** | |
| 757 | + * @param string|boolean $error_checking | |
| 758 | + */ | |
| 756 | 759 |    public function setErrorChecking($error_checking) { | 
| 757 | 760 | // Check up error-checking | 
| 758 | 761 |      if ($error_checking == FALSE) { | 
| @@ -40,7 +40,7 @@ discard block | ||
| 40 | 40 | |
| 41 | 41 | $this->setErrorChecking($error_checking); | 
| 42 | 42 | |
| 43 | -    if(is_object($xml)){ | |
| 43 | +    if (is_object($xml)) { | |
| 44 | 44 | $class = get_class($xml); | 
| 45 | 45 |        if ($class == 'DOMElement') { | 
| 46 | 46 | $this->appendChild($this->importNode($xml, true)); | 
| @@ -62,7 +62,7 @@ discard block | ||
| 62 | 62 | @$this->loadXML($xml, LIBXML_COMPACT); | 
| 63 | 63 | } | 
| 64 | 64 |        else if (!$this->loadXML($xml, LIBXML_COMPACT)) { | 
| 65 | -        trigger_error('BetterDOMDocument\DOMDoc: Could not load: ' . htmlspecialchars($xml), E_USER_WARNING); | |
| 65 | +        trigger_error('BetterDOMDocument\DOMDoc: Could not load: '.htmlspecialchars($xml), E_USER_WARNING); | |
| 66 | 66 | } | 
| 67 | 67 | } | 
| 68 | 68 | |
| @@ -327,7 +327,7 @@ discard block | ||
| 327 | 327 | $prefix = $parts[0]; | 
| 328 | 328 |          if (isset($namespaces[$prefix])) { | 
| 329 | 329 |            if (!strpos($root_match[0], "xmlns:$prefix")) { | 
| 330 | - $new_root .= " xmlns:$prefix='" . $namespaces[$prefix] . "'"; | |
| 330 | + $new_root .= " xmlns:$prefix='".$namespaces[$prefix]."'"; | |
| 331 | 331 | } | 
| 332 | 332 | } | 
| 333 | 333 | } | 
| @@ -336,7 +336,7 @@ discard block | ||
| 336 | 336 | |
| 337 | 337 | $dom = new DOMDoc($xml, $this->auto_ns); | 
| 338 | 338 |      if (!$dom->documentElement) { | 
| 339 | -      trigger_error('BetterDomDocument\DOMDoc Error: Invalid XML: ' . $xml); | |
| 339 | +      trigger_error('BetterDomDocument\DOMDoc Error: Invalid XML: '.$xml); | |
| 340 | 340 | } | 
| 341 | 341 | $element = $dom->documentElement; | 
| 342 | 342 | |
| @@ -448,7 +448,7 @@ discard block | ||
| 448 | 448 | $this->createContext($newnode, 'xml'); | 
| 449 | 449 | $this->createContext($context, 'xpath'); | 
| 450 | 450 | |
| 451 | -    if (!$context){ | |
| 451 | +    if (!$context) { | |
| 452 | 452 | return FALSE; | 
| 453 | 453 | } | 
| 454 | 454 | |
| @@ -526,7 +526,7 @@ discard block | ||
| 526 | 526 | |
| 527 | 527 |      if ($node) { | 
| 528 | 528 |        if (is_array($node) || get_class($node) == 'BetterDOMDocument\DOMList') { | 
| 529 | -        foreach($node as $item) { | |
| 529 | +        foreach ($node as $item) { | |
| 530 | 530 | $this->remove($item); | 
| 531 | 531 | } | 
| 532 | 532 | } | 
| @@ -598,7 +598,7 @@ discard block | ||
| 598 | 598 | $xsl = ' | 
| 599 | 599 | <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | 
| 600 | 600 | <xsl:template match="*"> | 
| 601 | -            <xsl:element name="' . $prefix . ':{local-name()}" namespace="' . $url . '"> | |
| 601 | +            <xsl:element name="' . $prefix.':{local-name()}" namespace="'.$url.'"> | |
| 602 | 602 | <xsl:copy-of select="@*"/> | 
| 603 | 603 | <xsl:apply-templates/> | 
| 604 | 604 | </xsl:element> | 
| @@ -610,7 +610,7 @@ discard block | ||
| 610 | 610 | } | 
| 611 | 611 |      else { | 
| 612 | 612 | // @@TODO: Report the correct calling file and number | 
| 613 | -      throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); | |
| 613 | +      throw new Exception("Changing the namespace of a ".get_class($node)." is not supported"); | |
| 614 | 614 | } | 
| 615 | 615 | } | 
| 616 | 616 | |
| @@ -685,7 +685,7 @@ discard block | ||
| 685 | 685 |        foreach ($this->getNamespaces() as $prefix => $url) { | 
| 686 | 686 | $namespaces = ''; | 
| 687 | 687 |          if ($prefix != 'xsl' && $prefix != 'xlink') { | 
| 688 | - $namespaces .= 'xmlns:' . $prefix . '="' . $url. '" '; | |
| 688 | + $namespaces .= 'xmlns:'.$prefix.'="'.$url.'" '; | |
| 689 | 689 | } | 
| 690 | 690 |          $xslOptions = str_replace("||namespaces||", $namespaces, $xslOptions); | 
| 691 | 691 | } | 
| @@ -724,8 +724,8 @@ discard block | ||
| 724 | 724 | |
| 725 | 725 | // Copy namespace prefixes | 
| 726 | 726 |      foreach ($this->ns as $prefix => $namespace) { | 
| 727 | -      if (!$context->hasAttribute('xmlns:' . $prefix)) { | |
| 728 | -        $context->setAttribute('xmlns:' . $prefix, $namespace); | |
| 727 | +      if (!$context->hasAttribute('xmlns:'.$prefix)) { | |
| 728 | +        $context->setAttribute('xmlns:'.$prefix, $namespace); | |
| 729 | 729 | } | 
| 730 | 730 | } | 
| 731 | 731 | |
| @@ -735,7 +735,7 @@ discard block | ||
| 735 | 735 | // The types listed are html "void" elements. | 
| 736 | 736 | // Find any of these elements that have no child nodes and are therefore candidates for self-closing, replace them with a self-closed version. | 
| 737 | 737 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; | 
| 738 | -      return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); | |
| 738 | +      return preg_replace('/'.$pattern.'/', '<$1$2/>', $output); | |
| 739 | 739 | } | 
| 740 | 740 |      else { | 
| 741 | 741 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); | 
| @@ -776,7 +776,7 @@ discard block | ||
| 776 | 776 | |
| 777 | 777 | // If it's an "XML" document, then get namespaces via xpath | 
| 778 | 778 | $xpath = new \DOMXPath($this); | 
| 779 | -    foreach($xpath->query('namespace::*') as $namespace) { | |
| 779 | +    foreach ($xpath->query('namespace::*') as $namespace) { | |
| 780 | 780 |        if (!empty($namespace->prefix)) { | 
| 781 | 781 |          if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { | 
| 782 | 782 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); | 
| @@ -814,8 +814,8 @@ discard block | ||
| 814 | 814 | } | 
| 815 | 815 | } | 
| 816 | 816 | } | 
| 817 | -        else if (substr($attr->name,0,6) == 'xmlns:') { | |
| 818 | - $prefix = substr($attr->name,6); | |
| 817 | +        else if (substr($attr->name, 0, 6) == 'xmlns:') { | |
| 818 | + $prefix = substr($attr->name, 6); | |
| 819 | 819 | $this->registerNamespace($prefix, $attr->value); | 
| 820 | 820 | } | 
| 821 | 821 | } | 
| @@ -44,24 +44,20 @@ discard block | ||
| 44 | 44 | $class = get_class($xml); | 
| 45 | 45 |        if ($class == 'DOMElement') { | 
| 46 | 46 | $this->appendChild($this->importNode($xml, true)); | 
| 47 | - } | |
| 48 | -      else if ($class == 'DOMDocument') { | |
| 47 | +      } else if ($class == 'DOMDocument') { | |
| 49 | 48 |          if ($xml->documentElement) { | 
| 50 | 49 | $this->appendChild($this->importNode($xml->documentElement, true)); | 
| 51 | 50 | } | 
| 52 | - } | |
| 53 | -      else if ($class == 'BetterDOMDocument\DOMDoc') { | |
| 51 | +      } else if ($class == 'BetterDOMDocument\DOMDoc') { | |
| 54 | 52 |          if ($xml->documentElement) { | 
| 55 | 53 | $this->appendChild($this->importNode($xml->documentElement, true)); | 
| 56 | 54 | } | 
| 57 | 55 | $this->ns = $xml->ns; | 
| 58 | 56 | } | 
| 59 | - } | |
| 60 | -    else if (is_string($xml) && !empty($xml)) { | |
| 57 | +    } else if (is_string($xml) && !empty($xml)) { | |
| 61 | 58 |        if ($this->error_checking == 'none') { | 
| 62 | 59 | @$this->loadXML($xml, LIBXML_COMPACT); | 
| 63 | - } | |
| 64 | -      else if (!$this->loadXML($xml, LIBXML_COMPACT)) { | |
| 60 | +      } else if (!$this->loadXML($xml, LIBXML_COMPACT)) { | |
| 65 | 61 |          trigger_error('BetterDOMDocument\DOMDoc: Could not load: ' . htmlspecialchars($xml), E_USER_WARNING); | 
| 66 | 62 | } | 
| 67 | 63 | } | 
| @@ -116,8 +112,7 @@ discard block | ||
| 116 | 112 |    public function lookupURL($prefix) { | 
| 117 | 113 |      if (isset($this->ns[$prefix])) { | 
| 118 | 114 | return $this->ns[$prefix]; | 
| 119 | - } | |
| 120 | -    else { | |
| 115 | +    } else { | |
| 121 | 116 | return FALSE; | 
| 122 | 117 | } | 
| 123 | 118 | } | 
| @@ -151,15 +146,13 @@ discard block | ||
| 151 | 146 | |
| 152 | 147 |      if ($context) { | 
| 153 | 148 | $result = $xob->query($xpath, $context); | 
| 154 | - } | |
| 155 | -    else { | |
| 149 | +    } else { | |
| 156 | 150 | $result = $xob->query($xpath); | 
| 157 | 151 | } | 
| 158 | 152 | |
| 159 | 153 |      if ($result) { | 
| 160 | 154 | return new DOMList($result, $this); | 
| 161 | - } | |
| 162 | -    else { | |
| 155 | +    } else { | |
| 163 | 156 | return FALSE; | 
| 164 | 157 | } | 
| 165 | 158 | } | 
| @@ -183,8 +176,7 @@ discard block | ||
| 183 | 176 | |
| 184 | 177 |      if (empty($result) || !count($result)) { | 
| 185 | 178 | return FALSE; | 
| 186 | - } | |
| 187 | -    else { | |
| 179 | +    } else { | |
| 188 | 180 | return $result->item(0); | 
| 189 | 181 | } | 
| 190 | 182 | } | 
| @@ -263,13 +255,11 @@ discard block | ||
| 263 | 255 |        if ($context->hasChildNodes()) { | 
| 264 | 256 |          if ($context->childNodes->length == 1 && $context->firstChild->nodeType == XML_TEXT_NODE) { | 
| 265 | 257 | $array['#text'] = $context->firstChild->nodeValue; | 
| 266 | - } | |
| 267 | -        else { | |
| 258 | +        } else { | |
| 268 | 259 |            foreach ($context->childNodes as $childNode) { | 
| 269 | 260 |              if ($childNode->nodeType == XML_ELEMENT_NODE) { | 
| 270 | 261 | $array[$childNode->nodeName][] = $this->getArray($raw, $childNode); | 
| 271 | - } | |
| 272 | -            elseif ($childNode->nodeType == XML_CDATA_SECTION_NODE) { | |
| 262 | +            } elseif ($childNode->nodeType == XML_CDATA_SECTION_NODE) { | |
| 273 | 263 | $array['#text'] = $childNode->textContent; | 
| 274 | 264 | } | 
| 275 | 265 | } | 
| @@ -301,8 +291,7 @@ discard block | ||
| 301 | 291 | $matches = array(); | 
| 302 | 292 |      if (preg_match($pattern, $this->saveXML($context), $matches)) { | 
| 303 | 293 | return $matches[1]; | 
| 304 | - } | |
| 305 | -    else { | |
| 294 | +    } else { | |
| 306 | 295 | return ''; | 
| 307 | 296 | } | 
| 308 | 297 | } | 
| @@ -372,8 +361,7 @@ discard block | ||
| 372 | 361 | |
| 373 | 362 |      if ($newnode->ownerDocument === $this) { | 
| 374 | 363 | $appendnode = $newnode; | 
| 375 | - } | |
| 376 | -    else { | |
| 364 | +    } else { | |
| 377 | 365 | $appendnode = $this->importNode($newnode, true); | 
| 378 | 366 | } | 
| 379 | 367 | |
| @@ -455,13 +443,11 @@ discard block | ||
| 455 | 443 |      if ($context->nextSibling) {  | 
| 456 | 444 | // $context has an immediate sibling : insert newnode before this one | 
| 457 | 445 | return $context->parentNode->insertBefore($newnode, $context->nextSibling); | 
| 458 | - } | |
| 459 | -    else {  | |
| 446 | +    } else {  | |
| 460 | 447 | // $context has no sibling next to it : insert newnode as last child of it's parent | 
| 461 | 448 |        if ($newnode->ownerDocument === $this) { | 
| 462 | 449 | $appendnode = $newnode; | 
| 463 | - } | |
| 464 | -      else { | |
| 450 | +      } else { | |
| 465 | 451 | $appendnode = $this->importNode($newnode, true); | 
| 466 | 452 | } | 
| 467 | 453 | return $context->parentNode->appendChild($appendnode); | 
| @@ -529,11 +515,9 @@ discard block | ||
| 529 | 515 |          foreach($node as $item) { | 
| 530 | 516 | $this->remove($item); | 
| 531 | 517 | } | 
| 532 | - } | |
| 533 | -      else if (get_class($node) == 'DOMNodeList') { | |
| 518 | +      } else if (get_class($node) == 'DOMNodeList') { | |
| 534 | 519 | $this->remove(new DOMList($node, $this)); | 
| 535 | - } | |
| 536 | -      else { | |
| 520 | +      } else { | |
| 537 | 521 | $parent = $node->parentNode; | 
| 538 | 522 | $parent->removeChild($node); | 
| 539 | 523 | } | 
| @@ -555,8 +539,7 @@ discard block | ||
| 555 | 539 |    public function tranform($xsl, $context = NULL) { | 
| 556 | 540 |      if (!$context) { | 
| 557 | 541 | $doc = $this; | 
| 558 | - } | |
| 559 | -    else { | |
| 542 | +    } else { | |
| 560 | 543 |        if (is_string($context)) { | 
| 561 | 544 | $context = $this->xpathSingle($context); | 
| 562 | 545 | } | 
| @@ -607,8 +590,7 @@ discard block | ||
| 607 | 590 | |
| 608 | 591 | $transformed = $this->tranform($xsl, $node); | 
| 609 | 592 | return $this->replace($node, $transformed->documentElement); | 
| 610 | - } | |
| 611 | -    else { | |
| 593 | +    } else { | |
| 612 | 594 | // @@TODO: Report the correct calling file and number | 
| 613 | 595 |        throw new Exception("Changing the namespace of a " . get_class($node) . " is not supported"); | 
| 614 | 596 | } | 
| @@ -693,14 +675,12 @@ discard block | ||
| 693 | 675 | // Add in xlink options | 
| 694 | 676 |        if ($options['xlink'] === TRUE) { | 
| 695 | 677 | $options['xlink'] = "@xlink:type = 'simple'"; | 
| 696 | - } | |
| 697 | -      else if (empty($options['xlink'])) { | |
| 678 | +      } else if (empty($options['xlink'])) { | |
| 698 | 679 | $options['xlink'] = "false()"; | 
| 699 | 680 | } | 
| 700 | 681 |        $xslOptions = str_replace("||xlink||", $options['xlink'], $xslOptions); | 
| 701 | 682 | $transformed = $this->tranform($xslOptions, $context); | 
| 702 | - } | |
| 703 | -    else { | |
| 683 | +    } else { | |
| 704 | 684 | $transformed = $this->tranform($xslSimple, $context); | 
| 705 | 685 | } | 
| 706 | 686 | |
| @@ -736,8 +716,7 @@ discard block | ||
| 736 | 716 | // Find any of these elements that have no child nodes and are therefore candidates for self-closing, replace them with a self-closed version. | 
| 737 | 717 | $pattern = '<(area|base|br|col|command|embed|hr|img|input|keygen|link|meta|param|source|track|wbr)(\b[^<]*)><\/\1>'; | 
| 738 | 718 |        return preg_replace('/' . $pattern . '/', '<$1$2/>', $output); | 
| 739 | - } | |
| 740 | -    else { | |
| 719 | +    } else { | |
| 741 | 720 | return $this->saveXML($context, LIBXML_NOEMPTYTAG); | 
| 742 | 721 | } | 
| 743 | 722 | } | 
| @@ -753,8 +732,7 @@ discard block | ||
| 753 | 732 | // Check up error-checking | 
| 754 | 733 |      if ($error_checking == FALSE) { | 
| 755 | 734 | $this->error_checking = 'none'; | 
| 756 | - } | |
| 757 | -    else { | |
| 735 | +    } else { | |
| 758 | 736 | $this->error_checking = $error_checking; | 
| 759 | 737 | } | 
| 760 | 738 |      if ($this->error_checking != 'strict') { | 
| @@ -781,8 +759,7 @@ discard block | ||
| 781 | 759 |          if ($namespace->prefix != 'xml' && $namespace->nodeValue != 'http://www.w3.org/XML/1998/namespace') { | 
| 782 | 760 | $this->registerNamespace($namespace->prefix, $namespace->nodeValue); | 
| 783 | 761 | } | 
| 784 | - } | |
| 785 | -      else { | |
| 762 | +      } else { | |
| 786 | 763 | $this->default_ns = $namespace->nodeValue; | 
| 787 | 764 |          if (is_string($auto_register_namespaces)) { | 
| 788 | 765 | $this->registerNamespace($auto_register_namespaces, $namespace->nodeValue); | 
| @@ -813,8 +790,7 @@ discard block | ||
| 813 | 790 | $this->registerNamespace($tagname, $attr->value); | 
| 814 | 791 | } | 
| 815 | 792 | } | 
| 816 | - } | |
| 817 | -        else if (substr($attr->name,0,6) == 'xmlns:') { | |
| 793 | +        } else if (substr($attr->name,0,6) == 'xmlns:') { | |
| 818 | 794 | $prefix = substr($attr->name,6); | 
| 819 | 795 | $this->registerNamespace($prefix, $attr->value); | 
| 820 | 796 | } | 
| @@ -21,7 +21,7 @@ | ||
| 21 | 21 | } | 
| 22 | 22 | |
| 23 | 23 | // Provides read-only access to $length and $dom | 
| 24 | -  public function __get ($prop) { | |
| 24 | +  public function __get($prop) { | |
| 25 | 25 |      if ($prop == 'length') { | 
| 26 | 26 | return $this->length; | 
| 27 | 27 | } | 
| @@ -24,11 +24,9 @@ discard block | ||
| 24 | 24 |    public function __get ($prop) { | 
| 25 | 25 |      if ($prop == 'length') { | 
| 26 | 26 | return $this->length; | 
| 27 | - } | |
| 28 | -    else if ($prop == 'dom') { | |
| 27 | +    } else if ($prop == 'dom') { | |
| 29 | 28 | return $this->dom; | 
| 30 | - } | |
| 31 | -    else { | |
| 29 | +    } else { | |
| 32 | 30 | return null; | 
| 33 | 31 | } | 
| 34 | 32 | } | 
| @@ -56,8 +54,9 @@ discard block | ||
| 56 | 54 |    public function item($index) { | 
| 57 | 55 |      if (isset($this->array[$index])) { | 
| 58 | 56 | return $this->array[$index]; | 
| 57 | +    } else { | |
| 58 | + return FALSE; | |
| 59 | 59 | } | 
| 60 | - else return FALSE; | |
| 61 | 60 | } | 
| 62 | 61 | |
| 63 | 62 |    public function count() { |