Skip to content

Commit

Permalink
Remove strict array typing to fill()
Browse files Browse the repository at this point in the history
  • Loading branch information
valzargaming committed Jan 17, 2025
1 parent 123328f commit a86f2b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Discord/Helpers/CollectionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function get(string $discrim, $key);
public function set($offset, $value);
public function pull($key, $default = null);
public function shift();
public function fill(array $items): self;
public function fill($items): self;
public function push(...$items): self;
public function pushItem($item): self;
public function count(): int;
Expand Down
10 changes: 8 additions & 2 deletions src/Discord/Helpers/CollectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,18 @@ public function shift()
/**
* Fills an array of items into the collection.
*
* @param array $items
* @param CollectionInterface|array $items
*
* @return self
*/
public function fill(array $items): self
public function fill($items): self
{
if ($items instanceof CollectionInterface) {
$items = $items->toArray();
}
if (! is_array($items)) {
throw new \InvalidArgumentException('The fill method only accepts arrays or CollectionInterface instances.');
}
foreach ($items as $item) {
$this->pushItem($item);
}
Expand Down

0 comments on commit a86f2b4

Please sign in to comment.