Skip to content

Commit

Permalink
Fix Bug
Browse files Browse the repository at this point in the history
  • Loading branch information
Vasiliy-Makogon committed Oct 7, 2023
1 parent af37553 commit 5b9b1e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
30 changes: 26 additions & 4 deletions src/CoverArray.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@

namespace Krugozor\Cover;

use ArrayAccess;
use ArrayIterator;
use Countable;
use IteratorAggregate;

/**
* Объектный массив.
*
* @package Krugozor\Cover
*/
class CoverArray implements \IteratorAggregate, \Countable, \ArrayAccess
class CoverArray implements IteratorAggregate, Countable, ArrayAccess
{
use Simple;

Expand Down Expand Up @@ -37,6 +43,21 @@ public function __set(string $key, mixed $value): void
$this->data[$key] = $this->array2cover($value);
}

/**
* @param iterable|null $data
* @return static
*/
public function setData(?iterable $data): static
{
if ($data) {
foreach ($data as $key => $value) {
$this->data[$key] = $this->array2cover($value);
}
}

return $this;
}

/**
* Реализация интерфейса Countable
*
Expand All @@ -50,11 +71,11 @@ final public function count(): int
/**
* Реализация интерфейса IteratorAggregate
*
* @return \ArrayIterator
* @return ArrayIterator
*/
final public function getIterator(): \ArrayIterator
final public function getIterator(): ArrayIterator
{
return new \ArrayIterator($this->data);
return new ArrayIterator($this->data);
}

/**
Expand Down Expand Up @@ -200,6 +221,7 @@ public function __unserialize(array $data): void
/**
* Возвращает массив с элементами в обратном порядке
*
* @param bool $preserve_keys
* @return array
* @see array_reverse
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function setData(?iterable $data): static
{
if ($data) {
foreach ($data as $key => $value) {
$this->$key = $value;
$this->data[$key] = $value;
}
}

Expand Down

0 comments on commit 5b9b1e2

Please sign in to comment.