@@ -1166,7 +1166,7 @@ protected function grabArticle(?\DOMElement $page = null)
1166
1166
for ($ c = $ candidates ->length - 1 ; $ c >= 0 ; --$ c ) {
1167
1167
$ node = $ candidates ->item ($ c );
1168
1168
// 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 )) {
1170
1170
$ this ->logger ->debug ('Removing unlikely candidate (using note) ' . $ node ->getNodePath () . ' by " ' . $ node ->tagName . '" with readability ' . self ::getContentScore ($ node ));
1171
1171
$ node ->parentNode ->removeChild ($ node );
1172
1172
}
@@ -1209,6 +1209,7 @@ protected function grabArticle(?\DOMElement $page = null)
1209
1209
}
1210
1210
}
1211
1211
1212
+ /** @var \DOMNodeList<\DOMElement> */
1212
1213
$ topCandidates = array_filter (
1213
1214
$ topCandidates ,
1214
1215
fn ($ v , $ idx ) => 0 === $ idx || null !== $ v ,
@@ -1326,19 +1327,19 @@ protected function grabArticle(?\DOMElement $page = null)
1326
1327
$ siblingNode = $ siblingNodes ->item ($ s );
1327
1328
$ siblingNodeName = $ siblingNode ->nodeName ;
1328
1329
$ 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 ' )) : '' ));
1330
1331
1331
1332
if ($ siblingNode ->isSameNode ($ topCandidate )) {
1332
1333
$ append = true ;
1333
1334
} else {
1334
1335
$ contentBonus = 0 ;
1335
1336
1336
1337
// 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 ' )) {
1338
1339
$ contentBonus += ((int ) $ topCandidate ->getAttribute ('readability ' )) * 0.2 ;
1339
1340
}
1340
1341
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 ) {
1342
1343
$ append = true ;
1343
1344
} elseif (0 === strcasecmp ($ siblingNodeName , 'p ' )) {
1344
1345
$ linkDensity = (int ) $ this ->getLinkDensity ($ siblingNode );
@@ -1568,7 +1569,7 @@ private function getAncestors(\DOMElement $node, int $maxDepth = 0): array
1568
1569
1569
1570
private function isPhrasingContent ($ node ): bool
1570
1571
{
1571
- return \ XML_TEXT_NODE === $ node-> nodeType
1572
+ return $ node instanceof \DOMText
1572
1573
|| \in_array (strtoupper ($ node ->nodeName ), $ this ->phrasingElements , true )
1573
1574
|| (
1574
1575
\in_array (strtoupper ($ node ->nodeName ), ['A ' , 'DEL ' , 'INS ' ], true )
0 commit comments