From e267d29b9ad1ecb192e6b6c54ca674ff4e651cef Mon Sep 17 00:00:00 2001 From: Saophalkun Ponlu Date: Fri, 2 Jun 2017 16:04:54 +1200 Subject: [PATCH] BUG Consistent return values for first and last methods --- src/ORM/ArrayList.php | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index 5d1ad744b..a358713b6 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -302,6 +302,10 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function first() { + if (empty($this->items)) { + return null; + } + return reset($this->items); } @@ -312,6 +316,10 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function last() { + if (empty($this->items)) { + return null; + } + return end($this->items); } @@ -514,12 +522,12 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function canFilterBy($by) { - $firstRecord = $this->first(); - - if ($firstRecord === false) { + if (empty($this->items)) { return false; } + $firstRecord = $this->first(); + return array_key_exists($by, $firstRecord); }