From 5040fc1587cde6c8d5ba9a9ee0e2ee13a3ea1cd3 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 11 Oct 2024 09:57:15 +0200 Subject: [PATCH] Use method param type hints instead of PHPDoc Since we require PHP 7.4, contravariance in param types is supported, so we do not need to worry about subclasses that widen the param type. It will be only breaking in the unlikely case a subclass uses a type that contradicts the PHPDoc type annotation and does not not extend `DOMNode`. Also fix the type annotation since some invocations pass it a `DOMText`, an arbitrary sibling/child `DOMNode` or even `null`. --- .php-cs-fixer.php | 1 + src/Readability.php | 6 +----- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php index 5f09a0c..b8b7aac 100644 --- a/.php-cs-fixer.php +++ b/.php-cs-fixer.php @@ -22,6 +22,7 @@ return (new PhpCsFixer\Config()) 'ordered_imports' => true, 'php_unit_strict' => false, 'phpdoc_order' => true, + 'phpdoc_to_param_type' => true, // 'psr4' => true, 'strict_comparison' => true, 'strict_param' => true, diff --git a/src/Readability.php b/src/Readability.php index 9c1b983..0bc2ec8 100644 --- a/src/Readability.php +++ b/src/Readability.php @@ -546,12 +546,8 @@ class Readability implements LoggerAwareInterface /** * Get the inner text of a node. * This also strips out any excess whitespace to be found. - * - * @param \DOMElement $e - * @param bool $normalizeSpaces (default: true) - * @param bool $flattenLines (default: false) */ - public function getInnerText($e, bool $normalizeSpaces = true, bool $flattenLines = false): string + public function getInnerText(?\DOMNode $e, bool $normalizeSpaces = true, bool $flattenLines = false): string { if (null === $e || !isset($e->textContent) || '' === $e->textContent) { return '';