Skip to content

Commit

Permalink
Merge pull request #4 from samilturgut/master
Browse files Browse the repository at this point in the history
Fixed \ArrayAccess object return types added.
  • Loading branch information
fustundag authored Dec 12, 2022
2 parents 0c4b3b5 + 3450a75 commit 0dc093f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Collection extends Model implements \Iterator, \Countable
{
protected $collection_key = 'items';

public function rewind()
public function rewind(): void
{
if (isset($this->{$this->collection_key})
&& is_array($this->{$this->collection_key})
Expand All @@ -20,51 +20,54 @@ public function rewind()
}
}

public function current()
public function current(): mixed
{
$this->coerceType($this->key());
if (is_array($this->{$this->collection_key})) {
return current($this->{$this->collection_key});
}
return false;
}

public function key()
public function key(): mixed
{
if (isset($this->{$this->collection_key})
&& is_array($this->{$this->collection_key})
) {
return key($this->{$this->collection_key});
}

return null;
}

public function next()
{
return next($this->{$this->collection_key});
}

public function valid()
public function valid(): bool
{
$key = $this->key();
return $key !== null && $key !== false;
}

public function count()
public function count(): int
{
if (!isset($this->{$this->collection_key})) {
return 0;
}
return count($this->{$this->collection_key});
}

public function offsetExists($offset)
public function offsetExists($offset): bool
{
if (!is_numeric($offset)) {
return parent::offsetExists($offset);
}
return isset($this->{$this->collection_key}[$offset]);
}

public function offsetGet($offset)
public function offsetGet($offset): mixed
{
if (!is_numeric($offset)) {
return parent::offsetGet($offset);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,12 +248,12 @@ public function assertIsArray($obj, $method)
}
}

public function offsetExists($offset)
public function offsetExists($offset): bool
{
return isset($this->$offset) || isset($this->modelData[$offset]);
}

public function offsetGet($offset)
public function offsetGet($offset): mixed
{
return $this->$offset ?? $this->__get($offset);
}
Expand Down

0 comments on commit 0dc093f

Please sign in to comment.