@@ -1166,7 +1166,7 @@ protected function grabArticle(?\DOMElement $page = null)
11661166 for ($ c = $ candidates ->length - 1 ; $ c >= 0 ; --$ c ) {
11671167 $ node = $ candidates ->item ($ c );
11681168 // node should be readable but not inside of an article otherwise it's probably non-readable block
1169- if ($ node ->hasAttribute ('readability ' ) && (int ) $ node ->getAttributeNode ('readability ' )->value < 40 && ($ node ->parentNode ? 0 !== strcasecmp ($ node ->parentNode ->tagName , 'article ' ) : true )) {
1169+ if ($ node ->hasAttribute ('readability ' ) && (int ) $ node ->getAttributeNode ('readability ' )->value < 40 && ($ node ->parentNode instanceof \DOMElement ? 0 !== strcasecmp ($ node ->parentNode ->tagName , 'article ' ) : true )) {
11701170 $ this ->logger ->debug ('Removing unlikely candidate (using note) ' . $ node ->getNodePath () . ' by " ' . $ node ->tagName . '" with readability ' . self ::getContentScore ($ node ));
11711171 $ node ->parentNode ->removeChild ($ node );
11721172 }
@@ -1209,6 +1209,7 @@ protected function grabArticle(?\DOMElement $page = null)
12091209 }
12101210 }
12111211
1212+ /** @var \DOMNodeList<\DOMElement> */
12121213 $ topCandidates = array_filter (
12131214 $ topCandidates ,
12141215 fn ($ v , $ idx ) => 0 === $ idx || null !== $ v ,
@@ -1326,19 +1327,19 @@ protected function grabArticle(?\DOMElement $page = null)
13261327 $ siblingNode = $ siblingNodes ->item ($ s );
13271328 $ siblingNodeName = $ siblingNode ->nodeName ;
13281329 $ append = false ;
1329- $ this ->logger ->debug ('Looking at sibling node: ' . $ siblingNode ->getNodePath () . ((\ XML_ELEMENT_NODE === $ siblingNode-> nodeType && $ siblingNode ->hasAttribute ('readability ' )) ? (' with score ' . $ siblingNode ->getAttribute ('readability ' )) : '' ));
1330+ $ this ->logger ->debug ('Looking at sibling node: ' . $ siblingNode ->getNodePath () . (($ siblingNode instanceof \DOMElement && $ siblingNode ->hasAttribute ('readability ' )) ? (' with score ' . $ siblingNode ->getAttribute ('readability ' )) : '' ));
13301331
13311332 if ($ siblingNode ->isSameNode ($ topCandidate )) {
13321333 $ append = true ;
13331334 } else {
13341335 $ contentBonus = 0 ;
13351336
13361337 // Give a bonus if sibling nodes and top candidates have the same classname.
1337- if (\ XML_ELEMENT_NODE === $ siblingNode-> nodeType && $ siblingNode ->getAttribute ('class ' ) === $ topCandidate ->getAttribute ('class ' ) && '' !== $ topCandidate ->getAttribute ('class ' )) {
1338+ if ($ siblingNode instanceof \DOMElement && $ siblingNode ->getAttribute ('class ' ) === $ topCandidate ->getAttribute ('class ' ) && '' !== $ topCandidate ->getAttribute ('class ' )) {
13381339 $ contentBonus += ((int ) $ topCandidate ->getAttribute ('readability ' )) * 0.2 ;
13391340 }
13401341
1341- if (\ XML_ELEMENT_NODE === $ siblingNode-> nodeType && $ siblingNode ->hasAttribute ('readability ' ) && (((int ) $ siblingNode ->getAttribute ('readability ' )) + $ contentBonus ) >= $ siblingScoreThreshold ) {
1342+ if ($ siblingNode instanceof \DOMElement && $ siblingNode ->hasAttribute ('readability ' ) && (((int ) $ siblingNode ->getAttribute ('readability ' )) + $ contentBonus ) >= $ siblingScoreThreshold ) {
13421343 $ append = true ;
13431344 } elseif (0 === strcasecmp ($ siblingNodeName , 'p ' )) {
13441345 $ linkDensity = (int ) $ this ->getLinkDensity ($ siblingNode );
@@ -1568,7 +1569,7 @@ private function getAncestors(\DOMElement $node, int $maxDepth = 0): array
15681569
15691570 private function isPhrasingContent ($ node ): bool
15701571 {
1571- return \ XML_TEXT_NODE === $ node-> nodeType
1572+ return $ node instanceof \DOMText
15721573 || \in_array (strtoupper ($ node ->nodeName ), $ this ->phrasingElements , true )
15731574 || (
15741575 \in_array (strtoupper ($ node ->nodeName ), ['A ' , 'DEL ' , 'INS ' ], true )
0 commit comments