From 32ba2119009e0174daffdc0654568076cfbe5ca5 Mon Sep 17 00:00:00 2001 From: Marcos Raudkett Date: Tue, 11 Jul 2023 23:46:30 +0300 Subject: [PATCH] Fix PHP 8+ deprecation warnings & errors. --- src/hQuery/Element.php | 10 +++++----- src/hQuery/Node.php | 45 +++++++++++++++++++++++++++++++----------- 2 files changed, 38 insertions(+), 17 deletions(-) diff --git a/src/hQuery/Element.php b/src/hQuery/Element.php index 49e20d2..6e4a1e4 100644 --- a/src/hQuery/Element.php +++ b/src/hQuery/Element.php @@ -108,7 +108,7 @@ public function __get($name) * @param int|string $offset * @param mixed $value */ - public function offsetSet($offset, $value) + public function offsetSet($offset, $value): void { if (is_null($offset)) { // $this->_data[] = $value; // ??? @@ -124,7 +124,7 @@ public function offsetSet($offset, $value) /** * @param int|string $offset */ - public function offsetGet($offset) + public function offsetGet($offset): mixed { return is_int($offset) ? $this->get($offset) // an element from collection @@ -136,7 +136,7 @@ public function offsetGet($offset) * @param int|string $offset * @return boolean */ - public function offsetExists($offset) + public function offsetExists($offset): bool { if (is_int($offset)) { return 0 <= $offset && $offset < count($this->ids); @@ -147,7 +147,7 @@ public function offsetExists($offset) /** * @param int|string $offset */ - public function offsetUnset($offset) + public function offsetUnset($offset): void { if (is_int($offset)) { $i = array_slice($this->ids, $offset, 1, true); @@ -166,7 +166,7 @@ public function offsetUnset($offset) * * @return hQuery_Element */ - public function current() + public function current(): mixed { $k = key($this->ids); if (null === $k) { diff --git a/src/hQuery/Node.php b/src/hQuery/Node.php index 5a982fa..27b7e8a 100644 --- a/src/hQuery/Node.php +++ b/src/hQuery/Node.php @@ -1136,15 +1136,23 @@ public function __unset($name) } // ------------------------------------------------------------------------ - // Countable: - public function count() + /** + * Countable: + * + * {@inheritdoc} + */ + public function count(): int { return isset($this->ids) ? count($this->ids) : 0; } // ------------------------------------------------------------------------ - // Iterable: - public function current() + /** + * Iterable: + * + * {@inheritdoc} + */ + public function current(): mixed { $k = key($this->ids); if (null === $k) { @@ -1154,33 +1162,46 @@ public function current() return array($k => $this->ids[$k]); } - public function valid() + /** + * {@inheritdoc} + */ + public function valid(): bool { return current($this->ids) !== false; } - public function key() + /** + * {@inheritdoc} + */ + public function key(): mixed { return key($this->ids); } - public function next() + /** + * {@inheritdoc} + */ + public function next(): void { - return next($this->ids) !== false ? $this->current() : false; + if (is_array($this->ids) && !empty($this->ids)) { + next($this->ids); + } } - public function prev() + /** + * {@inheritdoc} + */ + public function prev(): mixed { return prev($this->ids) !== false ? $this->current() : false; } /** - * @return array + * {@inheritdoc} */ - public function rewind() + public function rewind(): void { reset($this->ids); - return $this->current(); } // - Helpers ------------------------------------------------