From 5b0769186dc2d3bd62ae70b2615887969efc56a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Bottini?= Date: Mon, 19 Aug 2024 20:11:26 +0200 Subject: [PATCH 1/2] Update DOMQuery.php Fixes PHP8.1 deprecated notices for DOMQuery.php. --- src/QueryPath/DOMQuery.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/QueryPath/DOMQuery.php b/src/QueryPath/DOMQuery.php index 15ab8938..f85e763c 100644 --- a/src/QueryPath/DOMQuery.php +++ b/src/QueryPath/DOMQuery.php @@ -96,8 +96,8 @@ class DOMQuery implements \QueryPath\Query, \IteratorAggregate, \Countable { * An associative array of options. * @see qp() */ - public function __construct($document = NULL, $string = NULL, $options = array()) { - $string = trim($string); + public function __construct($document = NULL, $string = '', $options = array()) { + $string = trim((string) $string); $this->options = $options + Options::get() + $this->options; $parser_flags = isset($options['parser_flags']) ? $options['parser_flags'] : self::DEFAULT_PARSER_FLAGS; @@ -364,6 +364,7 @@ public function size() { * @return int * The number of matches in the DOMQuery. */ + #[\ReturnTypeWillChange] public function count() { return $this->matches->count(); } @@ -3985,6 +3986,7 @@ public function __call($name, $arguments) { * @return Iterable * Returns an iterator. */ + #[\ReturnTypeWillChange] public function getIterator() { $i = new QueryPathIterator($this->matches); $i->options = $this->options; From e7c583a298ce539cba27eb6b6d693e9c158c6bd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=A1s=20Bottini=20nicobot?= Date: Mon, 19 Aug 2024 20:25:39 +0200 Subject: [PATCH 2/2] Fixes PHP8.1 deprecated notices. --- src/QueryPath/CSS/Selector.php | 4 ++-- src/QueryPath/DOMQuery.php | 10 ++++------ src/QueryPath/QueryPathIterator.php | 4 ++-- 3 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/QueryPath/CSS/Selector.php b/src/QueryPath/CSS/Selector.php index 4b538bd8..7c55a1ea 100644 --- a/src/QueryPath/CSS/Selector.php +++ b/src/QueryPath/CSS/Selector.php @@ -58,7 +58,7 @@ public function __construct() { $this->selectors[$this->groupIndex][] = $this->currSelector; } - public function getIterator() { + public function getIterator(): \Traversable { return new \ArrayIterator($this->selectors); } @@ -73,7 +73,7 @@ public function toArray() { return $this->selectors; } - public function count() { + public function count():int { return count($this->selectors); } diff --git a/src/QueryPath/DOMQuery.php b/src/QueryPath/DOMQuery.php index f85e763c..fcb6bccc 100644 --- a/src/QueryPath/DOMQuery.php +++ b/src/QueryPath/DOMQuery.php @@ -7,7 +7,7 @@ * was done for a few reasons: * - The library has been refactored, and it made more sense to call the top * level class QueryPath. This is not the top level class. - * - There have been requests for a JSONQuery class, which would be the + * - There have been requests for a JSONQuery class, which would be the * natural complement of DOMQuery. */ @@ -97,7 +97,7 @@ class DOMQuery implements \QueryPath\Query, \IteratorAggregate, \Countable { * @see qp() */ public function __construct($document = NULL, $string = '', $options = array()) { - $string = trim((string) $string); + $string = trim( (string)$string ); $this->options = $options + Options::get() + $this->options; $parser_flags = isset($options['parser_flags']) ? $options['parser_flags'] : self::DEFAULT_PARSER_FLAGS; @@ -364,8 +364,7 @@ public function size() { * @return int * The number of matches in the DOMQuery. */ - #[\ReturnTypeWillChange] - public function count() { + public function count(): int { return $this->matches->count(); } @@ -3986,8 +3985,7 @@ public function __call($name, $arguments) { * @return Iterable * Returns an iterator. */ - #[\ReturnTypeWillChange] - public function getIterator() { + public function getIterator(): \Traversable { $i = new QueryPathIterator($this->matches); $i->options = $this->options; return $i; diff --git a/src/QueryPath/QueryPathIterator.php b/src/QueryPath/QueryPathIterator.php index be2e66f0..a39f75e2 100644 --- a/src/QueryPath/QueryPathIterator.php +++ b/src/QueryPath/QueryPathIterator.php @@ -18,8 +18,8 @@ class QueryPathIterator extends \IteratorIterator { public $options = array(); private $qp = NULL; - - public function current() { + + public function current(): mixed { if (!isset($this->qp)) { $this->qp = \QueryPath::with(parent::current(), NULL, $this->options); }