diff options
Diffstat (limited to 'vendor/ramsey/collection/src/AbstractCollection.php')
-rw-r--r-- | vendor/ramsey/collection/src/AbstractCollection.php | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/vendor/ramsey/collection/src/AbstractCollection.php b/vendor/ramsey/collection/src/AbstractCollection.php index 2facf0e89..d2cd1151c 100644 --- a/vendor/ramsey/collection/src/AbstractCollection.php +++ b/vendor/ramsey/collection/src/AbstractCollection.php @@ -32,6 +32,7 @@ use function array_uintersect; use function current; use function end; use function in_array; +use function is_int; use function reset; use function sprintf; use function unserialize; @@ -42,8 +43,8 @@ use function usort; * minimize the effort required to implement this interface * * @template T - * @template-extends AbstractArray<T> - * @template-implements CollectionInterface<T> + * @extends AbstractArray<T> + * @implements CollectionInterface<T> */ abstract class AbstractCollection extends AbstractArray implements CollectionInterface { @@ -238,7 +239,7 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt public function merge(CollectionInterface ...$collections): CollectionInterface { - $temp = [$this->data]; + $mergedCollection = clone $this; foreach ($collections as $index => $collection) { if (!$collection instanceof static) { @@ -255,16 +256,16 @@ abstract class AbstractCollection extends AbstractArray implements CollectionInt ); } - $temp[] = $collection->toArray(); + foreach ($collection as $key => $value) { + if (is_int($key)) { + $mergedCollection[] = $value; + } else { + $mergedCollection[$key] = $value; + } + } } - /** @var array<array-key, T> $merge */ - $merge = array_merge(...$temp); - - $collection = clone $this; - $collection->data = $merge; - - return $collection; + return $mergedCollection; } /** |