mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-09-30 05:09:06 +02:00
BUG Consistent return values for first and last methods
This commit is contained in:
parent
44f27645bd
commit
e267d29b9a
@ -302,6 +302,10 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
|
|||||||
*/
|
*/
|
||||||
public function first()
|
public function first()
|
||||||
{
|
{
|
||||||
|
if (empty($this->items)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return reset($this->items);
|
return reset($this->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -312,6 +316,10 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
|
|||||||
*/
|
*/
|
||||||
public function last()
|
public function last()
|
||||||
{
|
{
|
||||||
|
if (empty($this->items)) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
return end($this->items);
|
return end($this->items);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -514,12 +522,12 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
|
|||||||
*/
|
*/
|
||||||
public function canFilterBy($by)
|
public function canFilterBy($by)
|
||||||
{
|
{
|
||||||
$firstRecord = $this->first();
|
if (empty($this->items)) {
|
||||||
|
|
||||||
if ($firstRecord === false) {
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$firstRecord = $this->first();
|
||||||
|
|
||||||
return array_key_exists($by, $firstRecord);
|
return array_key_exists($by, $firstRecord);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user