File tree 1 file changed +14
-2
lines changed
1 file changed +14
-2
lines changed Original file line number Diff line number Diff line change @@ -797,9 +797,15 @@ public function pop($count = 1)
797
797
return array_pop ($ this ->items );
798
798
}
799
799
800
+ if ($ this ->isEmpty ()) {
801
+ return new static ;
802
+ }
803
+
800
804
$ results = [];
801
805
802
- foreach (range (1 , $ count ) as $ item ) {
806
+ $ collectionCount = $ this ->count ();
807
+
808
+ foreach (range (1 , min ($ count , $ collectionCount )) as $ item ) {
803
809
array_push ($ results , array_pop ($ this ->items ));
804
810
}
805
811
@@ -961,9 +967,15 @@ public function shift($count = 1)
961
967
return array_shift ($ this ->items );
962
968
}
963
969
970
+ if ($ this ->isEmpty ()) {
971
+ return new static ;
972
+ }
973
+
964
974
$ results = [];
965
975
966
- foreach (range (1 , $ count ) as $ item ) {
976
+ $ collectionCount = $ this ->count ();
977
+
978
+ foreach (range (1 , min ($ count , $ collectionCount )) as $ item ) {
967
979
array_push ($ results , array_shift ($ this ->items ));
968
980
}
969
981
You can’t perform that action at this time.
0 commit comments