Browse Source

Cleaning up

wrapper-classes
Dustin Wilson 3 years ago
parent
commit
71d6e17ec4
  1. 12
      lib/Document.php
  2. 8
      lib/ElementMap.php
  3. 6
      lib/traits/ChildNode.php
  4. 16
      lib/traits/NodeTrait.php
  5. 10
      lib/traits/ParentNode.php

12
lib/Document.php

@ -85,7 +85,7 @@ class Document extends \DOMDocument implements Node {
if ($this->_body !== null) {
# 2. Otherwise, if the new value is the same as the body element, return.
if ($value->isSameNode($this->_body)) {
if ($value === $this->_body) {
return;
}
@ -489,7 +489,7 @@ class Document extends \DOMDocument implements Node {
}
if ($node !== $this) {
if (!$node->ownerDocument->isSameNode($this)) {
if ($node->ownerDocument !== $this) {
throw new DOMException(DOMException::WRONG_DOCUMENT);
}
@ -553,7 +553,7 @@ class Document extends \DOMDocument implements Node {
protected function blockElementFilterFactory(\DOMNode $ignoredNode): \Closure {
return function($n) use ($ignoredNode) {
return (!$n->isSameNode($ignoredNode) && $n instanceof Element && $this->isHTMLNamespace($n) && (in_array($n->nodeName, self::BLOCK_ELEMENTS) || $n->walk(function($nn) {
return ($n !== $ignoredNode && $n instanceof Element && $this->isHTMLNamespace($n) && (in_array($n->nodeName, self::BLOCK_ELEMENTS) || $n->walk(function($nn) {
return ($nn instanceof Element && $this->isHTMLNamespace($nn) && in_array($nn->nodeName, self::BLOCK_ELEMENTS));
})->current() !== null));
};
@ -746,7 +746,7 @@ class Document extends \DOMDocument implements Node {
// the element is foreign and doesn't contain any children close the element
// instead and continue on to the next child node.
$hasChildNodes = $currentNode->hasChildNodes();
if (!$foreign || $hasChildNodes || ($foreign && !$hasChildNodes && ($foreignElement === null || $foreignElement->isSameNode($currentNode)))) {
if (!$foreign || $hasChildNodes || ($foreign && !$hasChildNodes && ($foreignElement === null || $foreignElement === $currentNode))) {
$s .= '>';
} elseif (!$hasChildNodes) {
$s .= '/>';
@ -796,10 +796,10 @@ class Document extends \DOMDocument implements Node {
}
}
if ($foreignElement !== null && $currentNode->isSameNode($foreignElement)) {
if ($foreignElement !== null && $currentNode === $foreignElement) {
$foreignElement = null;
$foreignElementWithBlockElementSiblings = false;
} elseif ($preformattedElement !== null && $currentNode->isSameNode($preformattedElement)) {
} elseif ($preformattedElement !== null && $currentNode === $preformattedElement) {
$preformattedElement = null;
}

8
lib/ElementMap.php

@ -32,7 +32,7 @@ class ElementMap {
}
foreach (self::$elements[$index] as $v) {
if ($v->isSameNode($element)) {
if ($v === $element) {
return false;
}
}
@ -46,7 +46,7 @@ class ElementMap {
$index = self::index($document);
if ($index !== -1) {
foreach (self::$elements[$index] as $k => $v) {
if ($v->isSameNode($element)) {
if ($v === $element) {
unset(self::$elements[$index][$k]);
self::$elements[$index] = array_values(self::$elements[$index]);
return true;
@ -75,7 +75,7 @@ class ElementMap {
$index = self::index($document);
if ($index !== -1) {
foreach (self::$elements[$index] as $v) {
if ($v->isSameNode($element)) {
if ($v === $element) {
return true;
}
}
@ -86,7 +86,7 @@ class ElementMap {
protected static function index(Document $document): int {
foreach (self::$documents as $k => $d) {
if ($d->isSameNode($document)) {
if ($d === $document) {
return $k;
}
}

6
lib/traits/ChildNode.php

@ -43,7 +43,7 @@ trait ChildNode {
$viableNextSibling = null;
while ($n = $n->nextSibling) {
foreach ($nodes as $nodeOrString) {
if ($nodeOrString instanceof \DOMNode && $nodeOrString->isSameNode($n)) {
if ($nodeOrString instanceof \DOMNode && $nodeOrString === $n) {
continue 2;
}
}
@ -92,7 +92,7 @@ trait ChildNode {
$viablePreviousSibling = null;
while ($n = $n->previousSibling) {
foreach ($nodes as $nodeOrString) {
if ($nodeOrString instanceof \DOMNode && $nodeOrString->isSameNode($n)) {
if ($nodeOrString instanceof \DOMNode && $nodeOrString === $n) {
continue 2;
}
}
@ -183,7 +183,7 @@ trait ChildNode {
$viableNextSibling = null;
while ($n = $n->nextSibling) {
foreach ($nodes as $nodeOrString) {
if ($nodeOrString instanceof \DOMNode && $nodeOrString->isSameNode($n)) {
if ($nodeOrString instanceof \DOMNode && $nodeOrString === $n) {
continue 2;
}
}

16
lib/traits/NodeTrait.php

@ -27,7 +27,7 @@ trait NodeTrait {
# The compareDocumentPosition(other) method steps are:
#
# 1. If this is other, then return zero.
if ($this->isSameNode($other)) {
if ($this === $other) {
return 0;
}
@ -56,12 +56,12 @@ trait NodeTrait {
# 1. For each attr in node2’s attribute list:
foreach ($node2->attributes as $attr) {
# 1. If attr equals attr1, then return the result of adding DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC and DOCUMENT_POSITION_PRECEDING.
if ($attr->isSameNode($attr1)) {
if ($attr === $attr1) {
return Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC + Node::DOCUMENT_POSITION_PRECEDING;
}
# 2. If attr equals attr2, then return the result of adding DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC and DOCUMENT_POSITION_FOLLOWING.
if ($attr->isSameNode($attr2)) {
if ($attr === $attr2) {
return Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC + Node::DOCUMENT_POSITION_FOLLOWING;
}
}
@ -81,15 +81,15 @@ trait NodeTrait {
self::$rand = rand(0, 1);
}
if ($node1 === null || $node2 === null || !$node1->getRootNode()->isSameNode($node2->getRootNode())) {
if ($node1 === null || $node2 === null || $node1->getRootNode() !== $node2->getRootNode()) {
return Node::DOCUMENT_POSITION_DISCONNECTED + Node::DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC + ((self::$rand === 0) ? Node::DOCUMENT_POSITION_PRECEDING : Node::DOCUMENT_POSITION_FOLLOWING);
}
# 7. If node1 is an ancestor of node2 and attr1 is null, or node1 is node2 and attr2
# is non-null, then return the result of adding DOCUMENT_POSITION_CONTAINS to
# DOCUMENT_POSITION_PRECEDING.
if (($node1->isSameNode($node2) && $attr2 !== null) || ($attr1 === null && $node2->moonwalk(function($n) use($node1) {
return ($n->isSameNode($node1));
if (($node1 === $node2 && $attr2 !== null) || ($attr1 === null && $node2->moonwalk(function($n) use($node1) {
return ($n === $node1);
})->current() !== null)) {
return Node::DOCUMENT_POSITION_CONTAINS + Node::DOCUMENT_POSITION_PRECEDING;
}
@ -98,14 +98,14 @@ trait NodeTrait {
# is non-null, then return the result of adding DOCUMENT_POSITION_CONTAINED_BY to
# DOCUMENT_POSITION_FOLLOWING.
if (($node1 === $node2 && $attr1 !== null) || ($attr2 === null && $node2->walk(function($n) use($node1) {
return ($n->isSameNode($node1));
return ($n === $node1);
})->current() !== null)) {
return Node::DOCUMENT_POSITION_CONTAINED_BY + Node::DOCUMENT_POSITION_FOLLOWING;
}
# 9. If node1 is preceding node2, then return DOCUMENT_POSITION_PRECEDING.
if ($node2->walkPreceding(function($n) use($node1) {
return ($n->isSameNode($node1));
return ($n === $node1);
})->current() !== null) {
return Node::DOCUMENT_POSITION_PRECEDING;
}

10
lib/traits/ParentNode.php

@ -168,16 +168,16 @@ trait ParentNode {
# A is an inclusive ancestor of B, or if B’s root has a non-null host and A is a
# host-including inclusive ancestor of B’s root’s host.
if ($node->parentNode !== null) {
if ($this->parentNode !== null && ($this->isSameNode($node) || $this->moonwalk(function($n) use($node) {
return ($n->isSameNode($node));
if ($this->parentNode !== null && ($this === $node || $this->moonwalk(function($n) use($node) {
return ($n === $node);
})->current() !== null)) {
throw new DOMException(DOMException::HIERARCHY_REQUEST_ERROR);
} else {
$parentRoot = $this->getRootNode();
if ($parentRoot instanceof DocumentFragment) {
$parentRootHost = $parentRoot->host;
if ($parentRootHost !== null && ($parentRootHost->isSameNode($node) || $parentRootHost->moonwalk(function($n) use ($node) {
return ($n->isSameNode($node));
if ($parentRootHost !== null && ($parentRootHost === $node || $parentRootHost->moonwalk(function($n) use ($node) {
return ($n === $node);
})->current() !== null)) {
throw new DOMException(DOMException::HIERARCHY_REQUEST_ERROR);
}
@ -187,7 +187,7 @@ trait ParentNode {
# 3. If child is non-null and its parent is not parent, then throw a
# "NotFoundError" DOMException.
if ($child !== null && ($child->parentNode === null || !$child->parentNode->isSameNode($this))) {
if ($child !== null && ($child->parentNode === null || $child->parentNode !== $this)) {
throw new DOMException(DOMException::NOT_FOUND);
}

Loading…
Cancel
Save