diff options
author | Andres Rey <[email protected]> | 2018-04-10 18:40:05 +0100 |
---|---|---|
committer | Andres Rey <[email protected]> | 2018-04-10 18:40:05 +0100 |
commit | b713a1dc6e0993b3804590baa1db5fc971c7973d (patch) | |
tree | 95f6f5491b03e535bac11b4f9fc99e4c28b492fe | |
parent | 4313981b814a3613971c1f9f7e8bb12504a09dc7 (diff) |
Remove extra check for DOMDocument nodes + add comment
-rw-r--r-- | src/Readability.php | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/Readability.php b/src/Readability.php index 17233c0..053d37f 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -997,6 +997,8 @@ class Readability $MINIMUM_TOPCANDIDATES = 3; if (count($alternativeCandidateAncestors) >= $MINIMUM_TOPCANDIDATES) { $parentOfTopCandidate = $topCandidate->parentNode; + + // Check if we are actually dealing with a DOMNode and not a DOMDocument node or higher while ($parentOfTopCandidate->nodeName !== 'body' && $parentOfTopCandidate->nodeType === XML_ELEMENT_NODE) { $listsContainingThisAncestor = 0; for ($ancestorIndex = 0; $ancestorIndex < count($alternativeCandidateAncestors) && $listsContainingThisAncestor < $MINIMUM_TOPCANDIDATES; $ancestorIndex++) { @@ -1027,8 +1029,7 @@ class Readability $scoreThreshold = $lastScore / 3; /* @var DOMElement $parentOfTopCandidate */ - // Check if we are actually dealing with a DOMNode and not a DOMDocument node or higher - while ($parentOfTopCandidate->nodeName !== 'body' && $parentOfTopCandidate->nodeType === XML_ELEMENT_NODE) { + while ($parentOfTopCandidate->nodeName !== 'body') { $parentScore = $parentOfTopCandidate->contentScore; if ($parentScore < $scoreThreshold) { break; @@ -1047,10 +1048,7 @@ class Readability // If the top candidate is the only child, use parent instead. This will help sibling // joining logic when adjacent content is actually located in parent's sibling node. $parentOfTopCandidate = $topCandidate->parentNode; - while ($parentOfTopCandidate->nodeName !== 'body' - && $parentOfTopCandidate->nodeType === XML_ELEMENT_NODE - && count($parentOfTopCandidate->getChildren(true)) === 1 - ) { + while ($parentOfTopCandidate->nodeName !== 'body' && count($parentOfTopCandidate->getChildren(true)) === 1) { $topCandidate = $parentOfTopCandidate; $parentOfTopCandidate = $topCandidate->parentNode; } |