fix: Deprecated: Return type ArrayAccess ixed

This commit is contained in:
Guillermo Pages
2023-11-24 16:04:47 +01:00
parent 86b781857f
commit 9a83c3b52e

View File

@@ -25,10 +25,6 @@ class OdbcResultSet implements \Iterator, \ArrayAccess, \Countable
return $this->num_rows; return $this->num_rows;
} }
public function count() {
return $this->get_num_rows();
}
public function is_error() public function is_error()
{ {
return ($this->error ? true : false); return ($this->error ? true : false);
@@ -49,78 +45,55 @@ class OdbcResultSet implements \Iterator, \ArrayAccess, \Countable
return $this->results; return $this->results;
} }
// ArrayAccess // Implementing Countable
/** public function count(): int {
* @param int $offset return $this->get_num_rows();
* @return bool
*/
public function offsetExists($offset)
{
return !$this->error && $this->cursor_index < $this->length && $this->cursor_index >= 0;
} }
/** // Implementing ArrayAccess
* @param int $offset public function offsetExists(mixed $offset): bool
* @return bool|array {
*/ return !$this->error && $offset < $this->length && $offset >= 0;
public function offsetGet($offset) }
public function offsetGet(mixed $offset): mixed
{ {
return $this->offsetExists($offset) ? $this->results[$offset] : false; return $this->offsetExists($offset) ? $this->results[$offset] : false;
} }
public function offsetSet($offset, $value) public function offsetSet(mixed $offset, mixed $value): void
{ {
if($this->offsetExists($offset)) { if($this->offsetExists($offset)) {
$this->results[$offset] = $value; $this->results[$offset] = $value;
} }
} }
public function offsetUnset($offset) public function offsetUnset(mixed $offset): void
{ {
throw new \RuntimeException("This makes no sense at all."); throw new \RuntimeException("Unsetting elements is not supported.");
} }
// Iterator // Implementing Iterator
/** public function current(): mixed
* Return the current element
* @return mixed
*/
public function current()
{ {
return $this->offsetGet($this->cursor_index); return $this->offsetGet($this->cursor_index);
} }
/**
* Return the key of the current element
* @return mixed
*/
public function key(): mixed public function key(): mixed
{ {
return $this->cursor_index; return $this->cursor_index;
} }
/**
* Move forward to next element
* @return void
*/
public function next(): void public function next(): void
{ {
++$this->cursor_index; ++$this->cursor_index;
} }
/**
* Rewind the Iterator to the first element
* @return void
*/
public function rewind(): void public function rewind(): void
{ {
$this->cursor_index = 0; $this->cursor_index = 0;
} }
/**
* Checks if current position is valid
* @return bool
*/
public function valid(): bool public function valid(): bool
{ {
return $this->offsetExists($this->cursor_index); return $this->offsetExists($this->cursor_index);