Skip to content

Commit

Permalink
Fix PHP 8+ deprecation warnings & errors.
Browse files Browse the repository at this point in the history
  • Loading branch information
elythi0n committed Jul 11, 2023
1 parent 3254dc0 commit 32ba211
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 17 deletions.
10 changes: 5 additions & 5 deletions src/hQuery/Element.php
Original file line number Diff line number Diff line change
Expand Up @@ -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; // ???
Expand All @@ -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
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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) {
Expand Down
45 changes: 33 additions & 12 deletions src/hQuery/Node.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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 ------------------------------------------------
Expand Down

0 comments on commit 32ba211

Please sign in to comment.