diff options
author | Andres Rey <[email protected]> | 2017-11-30 20:03:08 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2017-11-30 20:03:08 +0000 |
commit | 89555a061f7166a85c2a8ea0a7176067990c64a3 (patch) | |
tree | 634c268909fb708ef7678595e889f02576379352 | |
parent | 2345497c61e486aa1220bf4e092de9aee1d1e285 (diff) |
Remove duplicated function and fix calls
-rw-r--r-- | src/NodeClass/NodeClassTrait.php | 39 | ||||
-rw-r--r-- | src/NodeUtility.php | 10 | ||||
-rw-r--r-- | src/Readability.php | 8 |
3 files changed, 9 insertions, 48 deletions
diff --git a/src/NodeClass/NodeClassTrait.php b/src/NodeClass/NodeClassTrait.php index 0fad1f2..678b41e 100644 --- a/src/NodeClass/NodeClassTrait.php +++ b/src/NodeClass/NodeClassTrait.php @@ -220,45 +220,6 @@ trait NodeClassTrait } /** - * Returns the next node. First checks for children (if the flag allows it), then for siblings, and finally - * for parents. - * - * @param DOMNode|DOMText $originalNode - * @param bool $ignoreSelfAndKids - * - * @return DOMNode - */ - public function getNextNode($originalNode, $ignoreSelfAndKids = false) - { - /* - * Traverse the DOM from node to node, starting at the node passed in. - * Pass true for the second parameter to indicate this node itself - * (and its kids) are going away, and we want the next node over. - * - * Calling this in a loop will traverse the DOM depth-first. - */ - - // First check for kids if those aren't being ignored - if (!$ignoreSelfAndKids && $originalNode->firstChild) { - return $originalNode->firstChild; - } - - // Then for siblings... - if ($originalNode->nextSibling) { - return $originalNode->nextSibling; - } - - // And finally, move up the parent chain *and* find a sibling - // (because this is depth-first traversal, we will have already - // seen the parent nodes themselves). - do { - $originalNode = $originalNode->parentNode; - } while ($originalNode && !$originalNode->nextSibling); - - return ($originalNode) ? $originalNode->nextSibling : $originalNode; - } - - /** * Creates a new node based on the text content of the original node. * * @param $originalNode DOMElement diff --git a/src/NodeUtility.php b/src/NodeUtility.php index 1743aba..ca34c8c 100644 --- a/src/NodeUtility.php +++ b/src/NodeUtility.php @@ -58,7 +58,7 @@ class NodeUtility * Imported from the Element class on league\html-to-markdown * * @param $node - * @return mixed + * @return DOMElement */ public static function nextElement($node) { @@ -124,13 +124,13 @@ class NodeUtility } /** - * Remove the passed node. + * Remove the selected node. * - * @param DOMElement $node + * @param $node DOMElement * * @return void **/ - public static function removeNode(DOMElement $node) + public static function removeNode($node) { $parent = $node->parentNode; if ($parent) { @@ -140,7 +140,7 @@ class NodeUtility /** - * Returns the next node. First checks for childs (if the flag allows it), then for siblings, and finally + * Returns the next node. First checks for children (if the flag allows it), then for siblings, and finally * for parents. * * @param DOMNode $originalNode diff --git a/src/Readability.php b/src/Readability.php index 0684b7b..b80641e 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -563,7 +563,7 @@ class Readability } } - $node = $node->getNextNode($node); + $node = NodeUtility::getNextNode($node); } return $elementsToScore; @@ -1172,13 +1172,13 @@ class Readability **/ public function _cleanMatchedNodes($node, $regex) { - $endOfSearchMarkerNode = $node->getNextNode($node, true); - $next = $node->getNextNode($node); + $endOfSearchMarkerNode = NodeUtility::getNextNode($node, true); + $next = NodeUtility::getNextNode($node); while ($next && $next !== $endOfSearchMarkerNode) { if (preg_match($regex, sprintf('%s %s', $next->getAttribute('class'), $next->getAttribute('id')))) { $next = NodeUtility::removeAndGetNext($next); } else { - $next = $next->getNextNode($next); + $next = NodeUtility::getNextNode($next); } } } |