summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndres Rey <[email protected]>2018-04-26 18:26:56 +0100
committerAndres Rey <[email protected]>2018-04-26 18:26:56 +0100
commit2408d1a28915bc3b22b3675622e09cc1256cb5eb (patch)
tree8254c07206c858e7366d10de557d15358f576d53 /src
parentd7f1f36bf0bb480124b9e7b7930751766ee04137 (diff)
Remove $parseSuccessful flag
Diffstat (limited to 'src')
-rw-r--r--src/Readability.php36
1 files changed, 15 insertions, 21 deletions
diff --git a/src/Readability.php b/src/Readability.php
index 053d37f..d69897b 100644
--- a/src/Readability.php
+++ b/src/Readability.php
@@ -127,7 +127,7 @@ class Readability
*
* @throws ParseException
*
- * @return array|bool
+ * @return bool
*/
public function parse($html)
{
@@ -166,12 +166,9 @@ class Readability
$this->logger->info(sprintf('[Parsing] Article parsed. Amount of words: %s. Current threshold is: %s', $length, $this->configuration->getWordThreshold()));
- $parseSuccessful = true;
-
if ($result && $length < $this->configuration->getWordThreshold()) {
$this->dom = $this->loadHTML($html);
$root = $this->dom->getElementsByTagName('body')->item(0);
- $parseSuccessful = false;
if ($this->configuration->getStripUnlikelyCandidates()) {
$this->logger->debug('[Parsing] Threshold not met, trying again setting StripUnlikelyCandidates as false');
@@ -204,7 +201,6 @@ class Readability
$this->logger->debug('[Parsing] Threshold not met, but found some content in previous attempts.');
$result = $this->attempts[0]['articleContent'];
- $parseSuccessful = true;
break;
}
} else {
@@ -212,26 +208,24 @@ class Readability
}
}
- if ($parseSuccessful) {
- $result = $this->postProcessContent($result);
-
- // If we haven't found an excerpt in the article's metadata, use the article's
- // first paragraph as the excerpt. This can be used for displaying a preview of
- // the article's content.
- if (!$this->getExcerpt()) {
- $this->logger->debug('[Parsing] No excerpt text found on metadata, extracting first p node and using it as excerpt.');
- $paragraphs = $result->getElementsByTagName('p');
- if ($paragraphs->length > 0) {
- $this->setExcerpt(trim($paragraphs->item(0)->textContent));
- }
+ $result = $this->postProcessContent($result);
+
+ // If we haven't found an excerpt in the article's metadata, use the article's
+ // first paragraph as the excerpt. This can be used for displaying a preview of
+ // the article's content.
+ if (!$this->getExcerpt()) {
+ $this->logger->debug('[Parsing] No excerpt text found on metadata, extracting first p node and using it as excerpt.');
+ $paragraphs = $result->getElementsByTagName('p');
+ if ($paragraphs->length > 0) {
+ $this->setExcerpt(trim($paragraphs->item(0)->textContent));
}
+ }
- $this->setContent($result);
+ $this->setContent($result);
- $this->logger->info('*** Parse successful :)');
+ $this->logger->info('*** Parse successful :)');
- return true;
- }
+ return true;
}
/**