diff options
author | Andres Rey <[email protected]> | 2017-11-29 23:22:43 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2017-11-29 23:22:43 +0000 |
commit | 632db7d1cd28e81e3ea9dff816d1f324ded27760 (patch) | |
tree | b9345c392aa216501127c6aaf2cca138805a6ea9 | |
parent | 47043143fb0fb5d3b74a77499d620e77a0ac9940 (diff) |
Remove tagNameEqualsTo + comments
-rw-r--r-- | src/NodeClass/NodeClassTrait.php | 25 | ||||
-rw-r--r-- | src/Readability.php | 24 |
2 files changed, 19 insertions, 30 deletions
diff --git a/src/NodeClass/NodeClassTrait.php b/src/NodeClass/NodeClassTrait.php index 9dd6db7..18782c6 100644 --- a/src/NodeClass/NodeClassTrait.php +++ b/src/NodeClass/NodeClassTrait.php @@ -8,16 +8,22 @@ trait NodeClassTrait { /** + * Content score of the node. Used to determine the value of the content + * * @var int */ public $contentScore = 0; /** + * Flag for initialized status + * * @var bool */ private $initialized = false; /** + * Collection of regexps to check the node usability + * * @var array */ private $regexps = [ @@ -106,23 +112,6 @@ trait NodeClassTrait return ''; } - - /** - * Checks for the tag name. Case insensitive. - * - * @param string $value Name to compare to the current tag - * - * @return bool - */ - public function tagNameEqualsTo($value) - { - if (strtolower($value) === strtolower($this->nodeName)) { - return true; - } - - return false; - } - /** * Get the ancestors of the current node. * @@ -357,7 +346,7 @@ trait NodeClassTrait if ($maxDepth > 0 && $depth > $maxDepth) { return false; } - if ($node->parentNode->tagNameEqualsTo($tagName)) { + if ($node->parentNode->nodeName === $tagName) { return true; } $node = $node->parentNode; diff --git a/src/Readability.php b/src/Readability.php index 2c62ae6..55583ac 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -531,8 +531,8 @@ class Readability if ( preg_match($this->regexps['unlikelyCandidates'], $matchString) && !preg_match($this->regexps['okMaybeItsACandidate'], $matchString) && - !$node->tagNameEqualsTo('body') && - !$node->tagNameEqualsTo('a') + $node->nodeName !== 'body' && + $node->nodeName !== 'a' ) { $node = NodeUtility::removeAndGetNext($node); continue; @@ -540,10 +540,10 @@ class Readability } // Remove DIV, SECTION, and HEADER nodes without any content(e.g. text, image, video, or iframe). - if (($node->tagNameEqualsTo('div') || $node->tagNameEqualsTo('section') || $node->tagNameEqualsTo('header') || - $node->tagNameEqualsTo('h1') || $node->tagNameEqualsTo('h2') || $node->tagNameEqualsTo('h3') || - $node->tagNameEqualsTo('h4') || $node->tagNameEqualsTo('h5') || $node->tagNameEqualsTo('h6') || - $node->tagNameEqualsTo('p')) && + if (($node->nodeName === 'div' || $node->nodeName === 'section' || $node->nodeName === 'header' || + $node->nodeName === 'h1' || $node->nodeName === 'h2' || $node->nodeName === 'h3' || + $node->nodeName === 'h4' || $node->nodeName === 'h5' || $node->nodeName === 'h6' || + $node->nodeName === 'p') && $node->isElementWithoutContent()) { $node = NodeUtility::removeAndGetNext($node); continue; @@ -554,7 +554,7 @@ class Readability } // Turn all divs that don't have children block level elements into p's - if ($node->tagNameEqualsTo('div')) { + if ($node->nodeName === 'div') { /* * Sites like http://mobile.slate.com encloses each paragraph with a DIV * element. DIVs with only a P element inside and no text content can be @@ -835,7 +835,7 @@ class Readability * We also have to copy the body node so it is something we can modify. */ - if ($topCandidate === null || $topCandidate->tagNameEqualsTo('body')) { + if ($topCandidate === null || $topCandidate->nodeName === 'body') { // Move all of the page's children into topCandidate $topCandidate = new DOMDocument('1.0', 'utf-8'); $topCandidate->encoding = 'UTF-8'; @@ -863,7 +863,7 @@ class Readability $MINIMUM_TOPCANDIDATES = 3; if (count($alternativeCandidateAncestors) >= $MINIMUM_TOPCANDIDATES) { $parentOfTopCandidate = $topCandidate->parentNode; - while (!$parentOfTopCandidate->tagNameEqualsTo('body')) { + while ($parentOfTopCandidate->nodeName !== 'body') { $listsContainingThisAncestor = 0; for ($ancestorIndex = 0; $ancestorIndex < count($alternativeCandidateAncestors) && $listsContainingThisAncestor < $MINIMUM_TOPCANDIDATES; $ancestorIndex++) { $listsContainingThisAncestor += (int)in_array($parentOfTopCandidate, $alternativeCandidateAncestors[$ancestorIndex]); @@ -893,7 +893,7 @@ class Readability $scoreThreshold = $lastScore / 3; /* @var DOMElement $parentOfTopCandidate */ - while (!$parentOfTopCandidate->tagNameEqualsTo('body')) { + while ($parentOfTopCandidate->nodeName !== 'body') { $parentScore = $parentOfTopCandidate->contentScore; if ($parentScore < $scoreThreshold) { break; @@ -911,7 +911,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->tagNameEqualsTo('body') && count($parentOfTopCandidate->getChildren(true)) === 1) { + while ($parentOfTopCandidate->nodeName !== 'body' && count($parentOfTopCandidate->getChildren(true)) === 1) { $topCandidate = $parentOfTopCandidate; $parentOfTopCandidate = $topCandidate->parentNode; } @@ -948,7 +948,7 @@ class Readability } if ($sibling->contentScore + $contentBonus >= $siblingScoreThreshold) { $append = true; - } elseif ($sibling->tagNameEqualsTo('p')) { + } elseif ($sibling->nodeName === 'p') { $linkDensity = $sibling->getLinkDensity(); $nodeContent = $sibling->getTextContent(true); |