diff options
author | Andres Rey <[email protected]> | 2016-11-21 17:28:17 +0000 |
---|---|---|
committer | Andres Rey <[email protected]> | 2016-11-21 17:28:17 +0000 |
commit | 34f560cdb940d4bee5a072f63b03fefbe447b237 (patch) | |
tree | 892b1b2e4e60e6992725018f2d0c6bf2fefcb6b2 /src/Readability.php | |
parent | e24c61c22d7659446c8aa5d49bb18ababb717f3d (diff) |
Improved the way we catch calls to getAttribute to elements that lack of that function
Diffstat (limited to 'src/Readability.php')
-rw-r--r-- | src/Readability.php | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/src/Readability.php b/src/Readability.php index 8767752..17db281 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -53,7 +53,8 @@ class Readability extends Element implements ReadabilityInterface */ $score = 0; - if (!in_array(get_class($node), ['DOMDocument', 'DOMComment'])) { + // Check if the getAttribute is callable, as some elements lack of it (and calling it anyway throws an exception) + if (is_callable('getAttribute', false, $node)) { $hasScore = $node->getAttribute('data-readability'); if ($hasScore !== '') { // Node was initialized previously. Restoring score and setting flag. @@ -254,8 +255,8 @@ class Readability extends Element implements ReadabilityInterface */ public function setContentScore($score) { - if (!in_array(get_class($this->node), ['DOMDocument', 'DOMComment'])) { - + // Check if the getAttribute is callable, as some elements lack of it (and calling it anyway throws an exception) + if (is_callable('getAttribute', false, $node)) { $this->contentScore = (float)$score; // Set score in an attribute of the tag to prevent losing it while creating new Readability objects. |