Skip to content

Commit 063247b

Browse files
committed
fixup! Use JSLikeHTMLElement in type hints
1 parent ec8adea commit 063247b

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

src/Readability.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ class Readability implements LoggerAwareInterface
146146
protected $domainRegExp = null;
147147

148148
/**
149-
* @var ?\DOMElement
149+
* @var ?\JSLikeHTMLElement
150150
*/
151151
protected $body = null;
152152

@@ -603,7 +603,7 @@ public function getWordCount(string $text): int
603603
* This is the amount of text that is inside a link divided by the total text in the node.
604604
* Can exclude external references to differentiate between simple text and menus/infoblocks.
605605
*/
606-
public function getLinkDensity(\DOMElement $e, bool $excludeExternal = false): float
606+
public function getLinkDensity(JSLikeHTMLElement $e, bool $excludeExternal = false): float
607607
{
608608
$links = $e->getElementsByTagName('a');
609609
$textLength = mb_strlen($this->getInnerText($e, true, true));

stubs/dom.stub

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,18 @@ class DOMDocument
1111
/** @var JSLikeHTMLElement|null */
1212
public $documentElement;
1313

14-
/** @var null */
15-
public $ownerDocument;
16-
1714
/**
1815
* @param string $name
1916
* @return DOMNodeList<JSLikeHTMLElement>
2017
*/
2118
public function getElementsByTagName($name) {}
19+
20+
/**
21+
* @param string $localName
22+
* @param string $value
23+
* @return JSLikeHTMLElement Officially, this can return false but PHPStan decided to ignore that: <https://github.com/phpstan/phpstan-src/pull/1569>
24+
*/
25+
public function createElement($localName, $value = '') {}
2226
}
2327

2428
class DOMNode

0 commit comments

Comments
 (0)