Skip to content
Permalink
Browse files

Using variadic instead of call_user_func_array

  • Loading branch information...
jrbasso committed Dec 14, 2016
1 parent 1ab2eff commit 1f53eb67ea27f43d4c0ec3dbdac12cc363922c8d
@@ -443,13 +443,13 @@ public function runCommand($argv, $autoMethod = false, $extra = [])
array_shift($this->args);
$this->startup();
return call_user_func_array([$this, $method], $this->args);
return $this->$method(...$this->args);
}
if ($isMethod && isset($subcommands[$command])) {
$this->startup();
return call_user_func_array([$this, $method], $this->args);
return $this->$method(...$this->args);
}
if ($this->hasTask($command) && isset($subcommands[$command])) {
@@ -463,7 +463,7 @@ public function runCommand($argv, $autoMethod = false, $extra = [])
$this->command = 'main';
$this->startup();
return call_user_func_array([$this, 'main'], $this->args);
return $this->main(...$this->args);
}
$this->out($this->OptionParser->help($command));
@@ -206,7 +206,7 @@ public function startup(Event $event)
throw new RuntimeException(sprintf("Invalid callable for '%s' type.", $type));
}
if ($this->requestedWith($type)) {
$input = call_user_func_array([$request, 'input'], $handler);
$input = $request->input(...$handler);
$request->data = (array)$input;
}
}
@@ -432,7 +432,7 @@ public function invokeAction()
}
$callable = [$this, $request->param('action')];
return call_user_func_array($callable, $request->param('pass'));
return $callable(...$request->param('pass'));
}
/**
@@ -577,7 +577,7 @@ public function setAction($action, ...$args)
{
$this->request = $this->request->withParam('action', $action);
return call_user_func_array([&$this, $action], $args);
return $this->$action(...$args);
}
/**
@@ -456,7 +456,7 @@ public function __call($method, $arguments)
if (in_array($method, get_class_methods($resultSetClass))) {
$results = $this->all();
return call_user_func_array([$results, $method], $arguments);
return $results->$method(...$arguments);
}
throw new BadMethodCallException(
sprintf('Unknown method "%s"', $method)
@@ -66,17 +66,7 @@ public function __invoke()
protected function _call($args)
{
$callable = $this->_callable;
switch (count($args)) {
case 0:
return $callable();
case 1:
return $callable($args[0]);
case 2:
return $callable($args[0], $args[1]);
case 3:
return $callable($args[0], $args[1], $args[2]);
default:
return call_user_func_array($callable, $args);
}
return $callable(...$args);
}
}
@@ -403,34 +403,15 @@ public function dispatch($event)
/**
* Calls a listener.
*
* Direct callback invocation is up to 30% faster than using call_user_func_array.
* Optimize the common cases to provide improved performance.
*
* @param callable $listener The listener to trigger.
* @param \Cake\Event\Event $event Event instance.
* @return mixed The result of the $listener function.
*/
protected function _callListener(callable $listener, Event $event)
{
$data = $event->data();
$length = count($data);
if ($length) {
$data = array_values($data);
}
switch ($length) {
case 0:
return $listener($event);
case 1:
return $listener($event, $data[0]);
case 2:
return $listener($event, $data[0], $data[1]);
case 3:
return $listener($event, $data[0], $data[1], $data[2]);
default:
array_unshift($data, $event);
return call_user_func_array($listener, $data);
}
return $listener($event, ...array_values($data));
}
/**
@@ -238,11 +238,11 @@ public function read($sort = self::SORT_NAME, $exceptions = false, $fullPath = f
}
if ($dirs) {
$dirs = call_user_func_array('array_merge', $dirs);
$dirs = array_merge(...array_values($dirs));
}
if ($files) {
$files = call_user_func_array('array_merge', $files);
$files = array_merge(...array_values($files));
}
return [$dirs, $files];
@@ -587,7 +587,7 @@ public function __call($name, $params)
array_unshift($params, $type);
return call_user_func_array([$this, 'is'], $params);
return $this->is(...$params);
}
throw new BadMethodCallException(sprintf('Method %s does not exist', $name));
}
@@ -683,7 +683,7 @@ protected function _is($type, $args)
if (is_callable($detect)) {
array_unshift($args, $this);
return call_user_func_array($detect, $args);
return $detect(...$args);
}
if (isset($detect['env']) && $this->_environmentDetector($detect)) {
return true;
@@ -202,7 +202,7 @@ public function viewBuilder()
*/
public function __call($method, $args)
{
call_user_func_array([$this->_email, $method], $args);
$this->_email->$method(...$args);
return $this;
}
@@ -245,7 +245,7 @@ public function send($action, $args = [], $headers = [])
$this->_email->viewBuilder()->template($action);
}
call_user_func_array([$this, $action], $args);
$this->$action(...$args);
$result = $this->_email->send();
$this->reset();
@@ -1309,7 +1309,7 @@ public function __isset($property)
*/
public function __call($method, $argument)
{
return call_user_func_array([$this->target(), $method], $argument);
return $this->target()->$method(...$argument);
}
/**
@@ -163,6 +163,6 @@ public static function clear()
*/
public static function __callStatic($name, $arguments)
{
return call_user_func_array([static::locator(), $name], $arguments);
return static::locator()->$name(...$arguments);
}
}
@@ -928,7 +928,7 @@ public static function userDefined($check, $object, $method, $args = null)
E_USER_DEPRECATED
);
return call_user_func_array([$object, $method], [$check, $args]);
return $object->$method($check, $args);
}
/**
@@ -135,7 +135,7 @@ public function process($value, array $providers, array $context = [])
if ($this->_pass) {
$args = array_merge([$value], $this->_pass, [$context]);
$result = call_user_func_array($callable, $args);
$result = $callable(...$args);
} else {
$result = $callable($value, $context);
}
@@ -307,7 +307,7 @@ public function testInitializeContentTypeAndExtensionMismatch()
$this->RequestHandler->startup(new Event('Controller.startup', $this->Controller));
$this->assertNull($this->RequestHandler->ext);
call_user_func_array(['Cake\Routing\Router', 'extensions'], [$extensions, false]);
Router::extensions($extensions, false);
}
/**

0 comments on commit 1f53eb6

Please sign in to comment.
You can’t perform that action at this time.