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`.
pull/93/head
Jan Tojnar 1 year ago
parent 9a0a088bc6
commit 5040fc1587
  1. 1
      .php-cs-fixer.php
  2. 6
      src/Readability.php

@ -22,6 +22,7 @@ return (new PhpCsFixer\Config())
'ordered_imports' => true, 'ordered_imports' => true,
'php_unit_strict' => false, 'php_unit_strict' => false,
'phpdoc_order' => true, 'phpdoc_order' => true,
'phpdoc_to_param_type' => true,
// 'psr4' => true, // 'psr4' => true,
'strict_comparison' => true, 'strict_comparison' => true,
'strict_param' => true, 'strict_param' => true,

@ -546,12 +546,8 @@ class Readability implements LoggerAwareInterface
/** /**
* Get the inner text of a node. * Get the inner text of a node.
* This also strips out any excess whitespace to be found. * 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) { if (null === $e || !isset($e->textContent) || '' === $e->textContent) {
return ''; return '';

Loading…
Cancel
Save