Skip to content

Commit 1b59115

Browse files
committed
wip
1 parent 2982f30 commit 1b59115

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

src/Readability.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1207,13 +1207,13 @@ protected function grabArticle(?JSLikeHTMLElement $page = null)
12071207
}
12081208
}
12091209

1210-
/** @var \DOMNodeList<\DOMElement> */
12111210
$topCandidates = array_filter(
12121211
$topCandidates,
12131212
fn ($v, $idx) => 0 === $idx || null !== $v,
12141213
\ARRAY_FILTER_USE_BOTH
12151214
);
12161215
$topCandidate = $topCandidates[0];
1216+
\PHPStan\dumpType($topCandidates);
12171217

12181218
/*
12191219
* If we still have no top candidate, just use the body as a last resort.
@@ -1264,11 +1264,17 @@ protected function grabArticle(?JSLikeHTMLElement $page = null)
12641264
}
12651265
$parentOfTopCandidate = $parentOfTopCandidate->parentNode;
12661266
}
1267+
// For PHPStan: the loop terminates either when the parent node is body (a HTML element),
1268+
// or when $parentOfTopCandidate is in at least three candidate ancestor lists.
1269+
// TODO: Fuzz this.
1270+
\assert($parentOfTopCandidate instanceof JSLikeHTMLElement);
1271+
\assert($topCandidate instanceof JSLikeHTMLElement);
12671272
}
12681273
if (!$topCandidate->hasAttribute('readability')) {
12691274
$this->initializeNode($topCandidate);
12701275
}
12711276
$parentOfTopCandidate = $topCandidate->parentNode;
1277+
\assert($parentOfTopCandidate instanceof JSLikeHTMLElement);
12721278
$lastScore = (int) $topCandidate->getAttribute('readability');
12731279
$scoreThreshold = $lastScore / 3;
12741280
while ('body' !== $parentOfTopCandidate->nodeName) {
@@ -1552,6 +1558,9 @@ private function loadHtml(): void
15521558
$this->dom->registerNodeClass(\DOMElement::class, JSLikeHTMLElement::class);
15531559
}
15541560

1561+
/**
1562+
* @return array<JSLikeHTMLElement>
1563+
*/
15551564
private function getAncestors(JSLikeHTMLElement $node, int $maxDepth = 0): array
15561565
{
15571566
$ancestors = [];

0 commit comments

Comments
 (0)