From e4768e44b059abe83ff66ed717d31d78a37aac99 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Fri, 28 Sep 2018 10:56:15 +0200 Subject: [PATCH] Use splat over call_user_func_array and reduce calls to func_get_args() --- src/ORM/ArrayList.php | 18 +++++++++--------- src/ORM/DataList.php | 2 +- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ORM/ArrayList.php b/src/ORM/ArrayList.php index 10611ea3c..70edb5b9e 100644 --- a/src/ORM/ArrayList.php +++ b/src/ORM/ArrayList.php @@ -601,7 +601,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function filterAny() { - $keepUs = call_user_func_array([$this, 'normaliseFilterArgs'], func_get_args()); + $keepUs = $this->normaliseFilterArgs(...func_get_args()); $itemsToKeep = []; @@ -632,21 +632,22 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ protected function normaliseFilterArgs($column, $value = null) { - if (count(func_get_args())>2) { + $args = func_get_args(); + if (count($args) > 2) { throw new InvalidArgumentException('filter takes one array or two arguments'); } - if (count(func_get_args()) === 1 && !is_array(func_get_arg(0))) { + if (count($args) === 1 && !is_array($args[0])) { throw new InvalidArgumentException('filter takes one array or two arguments'); } $keepUs = []; - if (count(func_get_args()) === 2) { - $keepUs[func_get_arg(0)] = func_get_arg(1); + if (count($args) === 2) { + $keepUs[$args[0]] = $args[1]; } - if (count(func_get_args()) === 1 && is_array(func_get_arg(0))) { - foreach (func_get_arg(0) as $key => $val) { + if (count($args) === 1 && is_array($args[0])) { + foreach ($args[0] as $key => $val) { $keepUs[$key] = $val; } } @@ -718,8 +719,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L */ public function exclude() { - - $removeUs = call_user_func_array([$this, 'normaliseFilterArgs'], func_get_args()); + $removeUs = $this->normaliseFilterArgs(...func_get_args()); $hitsRequiredToRemove = count($removeUs); $matches = []; diff --git a/src/ORM/DataList.php b/src/ORM/DataList.php index 1f0caba3d..28f538e9f 100644 --- a/src/ORM/DataList.php +++ b/src/ORM/DataList.php @@ -132,7 +132,7 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li $list->inAlterDataQueryCall = true; try { - $res = call_user_func($callback, $list->dataQuery, $list); + $res = $callback($list->dataQuery, $list); if ($res) { $list->dataQuery = $res; }