From a86f2b40dd1d02e2b4384cad62587a0b61510434 Mon Sep 17 00:00:00 2001 From: Valithor Obsidion Date: Fri, 17 Jan 2025 18:47:01 -0500 Subject: [PATCH] Remove strict array typing to `fill()` --- src/Discord/Helpers/CollectionInterface.php | 2 +- src/Discord/Helpers/CollectionTrait.php | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/Discord/Helpers/CollectionInterface.php b/src/Discord/Helpers/CollectionInterface.php index e49a1ab98..797346f58 100644 --- a/src/Discord/Helpers/CollectionInterface.php +++ b/src/Discord/Helpers/CollectionInterface.php @@ -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; diff --git a/src/Discord/Helpers/CollectionTrait.php b/src/Discord/Helpers/CollectionTrait.php index 6fe542124..e2bd603cf 100644 --- a/src/Discord/Helpers/CollectionTrait.php +++ b/src/Discord/Helpers/CollectionTrait.php @@ -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); }