From 7e884f43985fae9e7d668043c7d126fe2221fa3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= <come@opensides.be> Date: Wed, 2 May 2018 16:07:57 +0200 Subject: [PATCH] :ambulance: fix(core) Use ... operator where it makes sense Instead of less readable func_get_args and call_user_func_array issue #5827 --- include/class_listing.inc | 11 ++++------- include/class_template.inc | 2 +- include/class_templateHandling.inc | 4 ++-- include/functions.inc | 5 ++--- plugins/admin/acl/class_aclManagement.inc | 5 ++--- plugins/admin/groups/class_roleGeneric.inc | 2 +- 6 files changed, 12 insertions(+), 17 deletions(-) diff --git a/include/class_listing.inc b/include/class_listing.inc index e6fc0fcb8..2a2276264 100644 --- a/include/class_listing.inc +++ b/include/class_listing.inc @@ -1110,16 +1110,13 @@ class listing /*! * \brief Filter link */ - function filterLink() + function filterLink($row, $dn, $mask, ...$vals) { - $row = func_get_arg(0); $pid = $this->pid; - $dn = func_get_arg(1); - $params = array(func_get_arg(2)); + $params = array($mask); // Collect sprintf params - for ($i = 3;$i < func_num_args();$i++) { - $val = func_get_arg($i); + foreach ($vals as $val) { if (empty($val)) { continue; } @@ -1138,7 +1135,7 @@ class listing $result = ' '; if (count($params) > 1) { - $trans = call_user_func_array('sprintf', $params); + $trans = sprintf(...$params); if ($trans != '') { return '<a href="?plug='.$_GET['plug'].'&PID='.$pid.'&act=listing_edit_'.$row.'" title="'.$dn.'">'.$trans.'</a>'; } diff --git a/include/class_template.inc b/include/class_template.inc index 0aaa6b6d3..f5897d3d7 100644 --- a/include/class_template.inc +++ b/include/class_template.inc @@ -276,7 +276,7 @@ class template $specialAttrs['caller'.strtoupper($attr)] = $ui->$attr; } $this->attrs = templateHandling::parseArray($this->attrs, $specialAttrs); - $this->tabObject->adapt_from_template($this->attrs, call_user_func_array('array_merge', $this->attributes)); + $this->tabObject->adapt_from_template($this->attrs, array_merge(...$this->attributes)); $this->applied = TRUE; return $this->tabObject; diff --git a/include/class_templateHandling.inc b/include/class_templateHandling.inc index d149e0e78..0fed84fa2 100644 --- a/include/class_templateHandling.inc +++ b/include/class_templateHandling.inc @@ -176,7 +176,7 @@ class templateHandling unset($attrs[$attr]); } } - $dependencies = array_unique(call_user_func_array('array_merge', $flatdepends)); + $dependencies = array_unique(array_merge(...$flatdepends)); foreach ($dependencies as $attr) { if (empty($flatdepends[$attr])) { $needed[] = $attr; @@ -515,7 +515,7 @@ class templateHandling $depends[$key] ); $array[] = $depends[$key]; - $cache[$key] = array_unique(call_user_func_array('array_merge_recursive', $array)); + $cache[$key] = array_unique(array_merge_recursive(...$array)); return $cache[$key]; } diff --git a/include/functions.inc b/include/functions.inc index 0a025c001..db0c03181 100644 --- a/include/functions.inc +++ b/include/functions.inc @@ -2512,9 +2512,8 @@ function mail_utf8($to, $from_user, $from_email, $subject, $message, $type = 'pl } /* Calls fopen, gives errors as an array if any, file handle if successful */ -function fopenWithErrorHandling() +function fopenWithErrorHandling(...$args) { - $args = func_get_args(); $errors = array(); set_error_handler( function ($errno, $errstr, $errfile, $errline, $errcontext) use (&$errors) @@ -2522,7 +2521,7 @@ function fopenWithErrorHandling() $errors[] = $errstr; } ); - $fh = @call_user_func_array('fopen', $args); + $fh = @fopen(...$args); restore_error_handler(); if ($fh !== FALSE) { return $fh; diff --git a/plugins/admin/acl/class_aclManagement.inc b/plugins/admin/acl/class_aclManagement.inc index ce0b9656a..f9e5735cc 100644 --- a/plugins/admin/acl/class_aclManagement.inc +++ b/plugins/admin/acl/class_aclManagement.inc @@ -201,14 +201,13 @@ class aclManagement extends simpleManagement @DEBUG (DEBUG_TRACE, __LINE__, __FUNCTION__, __FILE__, $this->dn, 'Creating new ACLĂ‚ assignment'); } - static function filterLabel($row, $dn, $pid = 0, $base = '') + static function filterLabel($row, $dn, $pid = 0, $base = '', ...$vals) { $ou = ''; if ($dn == $base) { $ou = ' . '; } else { - for ($i = 4;$i < func_num_args();$i++) { - $val = func_get_arg($i); + foreach ($vals as $val) { if (empty($val)) { continue; } diff --git a/plugins/admin/groups/class_roleGeneric.inc b/plugins/admin/groups/class_roleGeneric.inc index fabbb6a60..9569ee633 100644 --- a/plugins/admin/groups/class_roleGeneric.inc +++ b/plugins/admin/groups/class_roleGeneric.inc @@ -32,7 +32,7 @@ class RoleMembersAttribute extends UsersAttribute if (empty($groups)) { $this->whitelistDns = array(); } else { - $this->whitelistDns = call_user_func_array('array_merge_recursive', $groups)['member']; + $this->whitelistDns = array_merge_recursive(...$groups)['member']; } } return array( -- GitLab