Skip to content

Commit 47ab252

Browse files
committed
Add @var casts for XPath queries
Because PHPStan does not currently analyze XPath expressions, we need to use a @var cast: https://phpstan.org/writing-php-code/phpdocs-basics#inline-%40var These are list of elements since asterisk wildcard only selects elements: https://www.w3.org/TR/1999/REC-xpath-19991116/#path-abbrev
1 parent c471514 commit 47ab252

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/Readability.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,7 @@ public function prepArticle(\DOMNode $articleContent): void
474474
}
475475

476476
// Remove service data-candidate attribute.
477+
/** @var \DOMNodeList<\DOMElement> */
477478
$elems = $xpath->query('.//*[@data-candidate]', $articleContent);
478479
foreach ($elems as $elem) {
479480
$elem->removeAttribute('data-candidate');
@@ -1159,6 +1160,7 @@ protected function grabArticle(?\DOMElement $page = null)
11591160
* This is faster to do before scoring but safer after.
11601161
*/
11611162
if ($this->flagIsActive(self::FLAG_STRIP_UNLIKELYS) && $xpath) {
1163+
/** @var \DOMNodeList<\DOMElement> */
11621164
$candidates = $xpath->query('.//*[(self::footer and count(//footer)<2) or (self::aside and count(//aside)<2)]', $page->documentElement);
11631165

11641166
for ($c = $candidates->length - 1; $c >= 0; --$c) {
@@ -1180,6 +1182,7 @@ protected function grabArticle(?\DOMElement $page = null)
11801182
$topCandidates = array_fill(0, 5, null);
11811183
if ($xpath) {
11821184
// Using array of DOMElements after deletion is a path to DOOMElement.
1185+
/** @var \DOMNodeList<\DOMElement> */
11831186
$candidates = $xpath->query('.//*[@data-candidate]', $page->documentElement);
11841187
$this->logger->debug('Candidates: ' . $candidates->length);
11851188

0 commit comments

Comments
 (0)