Fix “A non well formed numeric value encountered”

pull/50/head
Jeremy Benoist 7 years ago
parent de1b1d9775
commit bb65caf864
No known key found for this signature in database
GPG Key ID: BCA73962457ACC3C
  1. 4
      src/Readability.php
  2. 2
      tests/ReadabilityTest.php

@ -61,7 +61,7 @@ class Readability implements LoggerAwareInterface
// constants // constants
const SCORE_CHARS_IN_PARAGRAPH = 100; const SCORE_CHARS_IN_PARAGRAPH = 100;
const SCORE_WORDS_IN_PARAGRAPH = 20; const SCORE_WORDS_IN_PARAGRAPH = 20;
const GRANDPARENT_SCORE_DIVISOR = 2.2; const GRANDPARENT_SCORE_DIVISOR = 2;
const MIN_PARAGRAPH_LENGTH = 20; const MIN_PARAGRAPH_LENGTH = 20;
const MIN_COMMAS_IN_PARAGRAPH = 6; const MIN_COMMAS_IN_PARAGRAPH = 6;
const MIN_ARTICLE_LENGTH = 200; const MIN_ARTICLE_LENGTH = 200;
@ -1115,7 +1115,7 @@ class Readability implements LoggerAwareInterface
// Add the score to the parent. The grandparent gets half. // Add the score to the parent. The grandparent gets half.
$parentNode->getAttributeNode('readability')->value += $contentScore; $parentNode->getAttributeNode('readability')->value += $contentScore;
if ($grandParentNode) { if ($grandParentNode) {
$grandParentNode->getAttributeNode('readability')->value += $contentScore / self::GRANDPARENT_SCORE_DIVISOR; $grandParentNode->getAttributeNode('readability')->value += round($contentScore / self::GRANDPARENT_SCORE_DIVISOR);
} }
} }

@ -193,7 +193,7 @@ class ReadabilityTest extends \PHPUnit\Framework\TestCase
$this->assertEmpty($readability->getTitle()->getInnerHtml()); $this->assertEmpty($readability->getTitle()->getInnerHtml());
$this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml()); $this->assertContains('This is an awesome text with some links, here there are', $readability->getContent()->getInnerHtml());
$this->assertNotContains('<aside>', $readability->getContent()->getInnerHtml()); $this->assertNotContains('<aside>', $readability->getContent()->getInnerHtml());
$this->assertContains('<footer readability="4"/>', $readability->getContent()->getInnerHtml()); $this->assertContains('<footer readability="5"/>', $readability->getContent()->getInnerHtml());
} }
public function testWithClasses() public function testWithClasses()

Loading…
Cancel
Save