diff options
-rw-r--r-- | src/Configuration.php | 36 | ||||
-rw-r--r-- | src/Readability.php | 4 | ||||
-rw-r--r-- | test/ConfigurationTest.php | 2 |
3 files changed, 35 insertions, 7 deletions
diff --git a/src/Configuration.php b/src/Configuration.php index 951740e..65905b8 100644 --- a/src/Configuration.php +++ b/src/Configuration.php @@ -21,7 +21,7 @@ class Configuration /** * @var int */ - protected $wordThreshold = 500; + protected $charThreshold = 500; /** * @var bool @@ -149,19 +149,45 @@ class Configuration /** * @return int */ + public function getCharThreshold() + { + return $this->charThreshold; + } + + /** + * @param int $charThreshold + * + * @return $this + */ + public function setCharThreshold($charThreshold) + { + $this->charThreshold = $charThreshold; + + return $this; + } + + /** + * @deprecated Use getCharThreshold. Will be removed in version 2.0 + * + * @return int + */ public function getWordThreshold() { - return $this->wordThreshold; + @trigger_error('getWordThreshold was replaced with getCharThreshold and will be removed in version 2.0', E_USER_DEPRECATED); + + return $this->charThreshold; } /** - * @param int $wordThreshold + * @param int $charThreshold * * @return $this */ - public function setWordThreshold($wordThreshold) + public function setWordThreshold($charThreshold) { - $this->wordThreshold = $wordThreshold; + @trigger_error('setWordThreshold was replaced with setCharThreshold and will be removed in version 2.0', E_USER_DEPRECATED); + + $this->charThreshold = $charThreshold; return $this; } diff --git a/src/Readability.php b/src/Readability.php index b8b5b5b..c7c3d50 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -164,9 +164,9 @@ class Readability $length = mb_strlen(preg_replace(NodeUtility::$regexps['onlyWhitespace'], '', $result->textContent)); - $this->logger->info(sprintf('[Parsing] Article parsed. Amount of words: %s. Current threshold is: %s', $length, $this->configuration->getWordThreshold())); + $this->logger->info(sprintf('[Parsing] Article parsed. Amount of words: %s. Current threshold is: %s', $length, $this->configuration->getCharThreshold())); - if ($result && $length < $this->configuration->getWordThreshold()) { + if ($result && $length < $this->configuration->getCharThreshold()) { $this->dom = $this->loadHTML($html); $root = $this->dom->getElementsByTagName('body')->item(0); diff --git a/test/ConfigurationTest.php b/test/ConfigurationTest.php index 19db2f1..b304b40 100644 --- a/test/ConfigurationTest.php +++ b/test/ConfigurationTest.php @@ -40,6 +40,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase private function doEqualsAsserts(Configuration $config, array $options) { $this->assertEquals($options['maxTopCandidates'], $config->getMaxTopCandidates()); + $this->assertEquals($options['charThreshold'], $config->getCharThreshold()); $this->assertEquals($options['wordThreshold'], $config->getWordThreshold()); $this->assertEquals($options['articleByLine'], $config->getArticleByLine()); $this->assertEquals($options['stripUnlikelyCandidates'], $config->getStripUnlikelyCandidates()); @@ -61,6 +62,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase 'All current parameters' => [ 'maxTopCandidates' => 3, 'wordThreshold' => 500, + 'charThreshold' => 500, 'articleByLine' => true, 'stripUnlikelyCandidates' => false, 'cleanConditionally' => false, |