Skip to content

Commit d17728b

Browse files
committed
Merge branch '8.x'
# Conflicts: # composer.json # src/Illuminate/Foundation/Application.php # src/Illuminate/Mail/composer.json # src/Illuminate/Queue/composer.json
2 parents bf98012 + c768da2 commit d17728b

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

Collection.php

+14-2
Original file line numberDiff line numberDiff line change
@@ -797,9 +797,15 @@ public function pop($count = 1)
797797
return array_pop($this->items);
798798
}
799799

800+
if ($this->isEmpty()) {
801+
return new static;
802+
}
803+
800804
$results = [];
801805

802-
foreach (range(1, $count) as $item) {
806+
$collectionCount = $this->count();
807+
808+
foreach (range(1, min($count, $collectionCount)) as $item) {
803809
array_push($results, array_pop($this->items));
804810
}
805811

@@ -961,9 +967,15 @@ public function shift($count = 1)
961967
return array_shift($this->items);
962968
}
963969

970+
if ($this->isEmpty()) {
971+
return new static;
972+
}
973+
964974
$results = [];
965975

966-
foreach (range(1, $count) as $item) {
976+
$collectionCount = $this->count();
977+
978+
foreach (range(1, min($count, $collectionCount)) as $item) {
967979
array_push($results, array_shift($this->items));
968980
}
969981

0 commit comments

Comments
 (0)