mirror of
https://github.com/silverstripe/silverstripe-framework
synced 2024-10-22 12:05:37 +00:00
Use splat over call_user_func_array and reduce calls to func_get_args()
This commit is contained in:
parent
1b0293d8c5
commit
e4768e44b0
@ -601,7 +601,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
|
|||||||
*/
|
*/
|
||||||
public function filterAny()
|
public function filterAny()
|
||||||
{
|
{
|
||||||
$keepUs = call_user_func_array([$this, 'normaliseFilterArgs'], func_get_args());
|
$keepUs = $this->normaliseFilterArgs(...func_get_args());
|
||||||
|
|
||||||
$itemsToKeep = [];
|
$itemsToKeep = [];
|
||||||
|
|
||||||
@ -632,21 +632,22 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
|
|||||||
*/
|
*/
|
||||||
protected function normaliseFilterArgs($column, $value = null)
|
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');
|
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');
|
throw new InvalidArgumentException('filter takes one array or two arguments');
|
||||||
}
|
}
|
||||||
|
|
||||||
$keepUs = [];
|
$keepUs = [];
|
||||||
if (count(func_get_args()) === 2) {
|
if (count($args) === 2) {
|
||||||
$keepUs[func_get_arg(0)] = func_get_arg(1);
|
$keepUs[$args[0]] = $args[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count(func_get_args()) === 1 && is_array(func_get_arg(0))) {
|
if (count($args) === 1 && is_array($args[0])) {
|
||||||
foreach (func_get_arg(0) as $key => $val) {
|
foreach ($args[0] as $key => $val) {
|
||||||
$keepUs[$key] = $val;
|
$keepUs[$key] = $val;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -718,8 +719,7 @@ class ArrayList extends ViewableData implements SS_List, Filterable, Sortable, L
|
|||||||
*/
|
*/
|
||||||
public function exclude()
|
public function exclude()
|
||||||
{
|
{
|
||||||
|
$removeUs = $this->normaliseFilterArgs(...func_get_args());
|
||||||
$removeUs = call_user_func_array([$this, 'normaliseFilterArgs'], func_get_args());
|
|
||||||
|
|
||||||
$hitsRequiredToRemove = count($removeUs);
|
$hitsRequiredToRemove = count($removeUs);
|
||||||
$matches = [];
|
$matches = [];
|
||||||
|
@ -132,7 +132,7 @@ class DataList extends ViewableData implements SS_List, Filterable, Sortable, Li
|
|||||||
$list->inAlterDataQueryCall = true;
|
$list->inAlterDataQueryCall = true;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$res = call_user_func($callback, $list->dataQuery, $list);
|
$res = $callback($list->dataQuery, $list);
|
||||||
if ($res) {
|
if ($res) {
|
||||||
$list->dataQuery = $res;
|
$list->dataQuery = $res;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user