Merge pull request #6987 from open-sausages/pull/4.0/3239-consisten-fist-last-returns

Consistent return values for first and last methods
This commit is contained in:
Daniel Hensby 2017-06-06 16:59:04 +01:00 committed by GitHub
commit 856aa79892

View File

@ -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);
}