From abf670d02e2aea904d73cc2788e993f2f30693a3 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 12 Oct 2024 02:04:14 +0200 Subject: [PATCH] fixup! Use JSLikeHTMLElement in type hints --- src/Readability.php | 4 ++-- stubs/dom.stub | 10 +++++++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Readability.php b/src/Readability.php index 97d53f0..5c36b71 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -146,7 +146,7 @@ class Readability implements LoggerAwareInterface protected $domainRegExp = null; /** - * @var ?\DOMElement + * @var ?\JSLikeHTMLElement */ protected $body = null; @@ -603,7 +603,7 @@ class Readability implements LoggerAwareInterface * This is the amount of text that is inside a link divided by the total text in the node. * Can exclude external references to differentiate between simple text and menus/infoblocks. */ - public function getLinkDensity(\DOMElement $e, bool $excludeExternal = false): float + public function getLinkDensity(JSLikeHTMLElement $e, bool $excludeExternal = false): float { $links = $e->getElementsByTagName('a'); $textLength = mb_strlen($this->getInnerText($e, true, true)); diff --git a/stubs/dom.stub b/stubs/dom.stub index ac85e9d..09a39d6 100644 --- a/stubs/dom.stub +++ b/stubs/dom.stub @@ -11,14 +11,18 @@ class DOMDocument /** @var JSLikeHTMLElement|null */ public $documentElement; - /** @var null */ - public $ownerDocument; - /** * @param string $name * @return DOMNodeList */ public function getElementsByTagName($name) {} + + /** + * @param string $localName + * @param string $value + * @return JSLikeHTMLElement Officially, this can return false but PHPStan decided to ignore that: + */ + public function createElement($localName, $value = '') {} } class DOMNode