summaryrefslogtreecommitdiff
path: root/src/HTMLParser.php
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2016-10-21 20:20:48 +0100
committerAndres Rey <[email protected]>2016-10-21 20:20:48 +0100
commit0c11d557755ddbbafeeccd71e2d70b5c1d1458ab (patch)
treefcef7e334ff98025c1b60e2a1b3600296097e45b /src/HTMLParser.php
parentfe73c4d7cf71023c4cc5654afb0aea47b179c084 (diff)
Major refactor, Readability now is an extension of Element.
Diffstat (limited to 'src/HTMLParser.php')
-rw-r--r--src/HTMLParser.php13
1 files changed, 7 insertions, 6 deletions
diff --git a/src/HTMLParser.php b/src/HTMLParser.php
index 133a513..2f54114 100644
--- a/src/HTMLParser.php
+++ b/src/HTMLParser.php
@@ -89,7 +89,7 @@ class HTMLParser
throw new \InvalidArgumentException('Invalid HTML was provided');
}
- $root = new DOMElement($root);
+ $root = new Readability($root);
$this->getNodes($root);
@@ -139,7 +139,7 @@ class HTMLParser
{
$metadata = [];
foreach ($this->dom->getElementsByTagName('meta') as $meta) {
- /* @var DOMElement $meta */
+ /* @var Readability $meta */
$name = $meta->getAttribute('name');
$property = $meta->getAttribute('property');
@@ -213,9 +213,9 @@ class HTMLParser
/**
* Gets nodes from the root element.
*
- * @param $node DOMElementInterface
+ * @param $node ReadabilityInterface
*/
- private function getNodes(DOMElementInterface $node)
+ private function getNodes(ReadabilityInterface $node)
{
$matchString = $node->getAttribute('class') . ' ' . $node->getAttribute('id');
@@ -257,6 +257,7 @@ class HTMLParser
{
$candidates = [];
+ /** @var Readability $node */
foreach ($nodes as $node) {
// Discard nodes with less than 25 characters
@@ -281,9 +282,9 @@ class HTMLParser
$contentScore += min(floor(strlen($node->getValue()) / 100), 3);
// Initialize and score ancestors.
+ /** @var Readability $ancestor */
foreach ($ancestors as $level => $ancestor) {
- $readability = new Readability($ancestor);
- $readability = $readability->initializeNode();
+ $readability = $ancestor->initializeNode();
/*
* Node score divider: