Skip to content

Commit

Permalink
[5.3] Eloquent Builder - Avoid call_user_func_array (#16936)
Browse files Browse the repository at this point in the history
* [5.3] Eloquent Builder - Avoid call_user_func_array

* Some changes
  • Loading branch information
KennedyTedesco authored and taylorotwell committed Dec 23, 2016
1 parent 038840d commit dd3c081
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,7 @@ public function chunk($count, callable $callback)
// On each chunk result set, we will pass them to the callback and then let the
// developer take care of everything within the callback, which allows us to
// keep the memory low for spinning through large result sets for working.
if (call_user_func($callback, $results) === false) {
if ($callback($results) === false) {
return false;
}

Expand Down Expand Up @@ -421,7 +421,7 @@ public function chunkById($count, callable $callback, $column = 'id')
break;
}

if (call_user_func($callback, $results) === false) {
if ($callback($results) === false) {
return false;
}

Expand Down Expand Up @@ -598,7 +598,9 @@ protected function addUpdatedAtColumn(array $values)
public function delete()
{
if (isset($this->onDelete)) {
return call_user_func($this->onDelete, $this);
$closure = $this->onDelete;

return $closure($this);
}

return $this->toBase()->delete();
Expand Down Expand Up @@ -677,7 +679,7 @@ protected function loadRelation(array $models, $name, Closure $constraints)

$relation->addEagerConstraints($models);

call_user_func($constraints, $relation);
$constraints($relation);

$models = $relation->initRelation($models, $name);

Expand Down Expand Up @@ -769,9 +771,9 @@ public function when($value, $callback, $default = null)
$builder = $this;

if ($value) {
$builder = call_user_func($callback, $builder);
$builder = $callback($builder);
} elseif ($default) {
$builder = call_user_func($default, $builder);
$builder = $default($builder);
}

return $builder;
Expand All @@ -791,11 +793,11 @@ public function where($column, $operator = null, $value = null, $boolean = 'and'
if ($column instanceof Closure) {
$query = $this->model->newQueryWithoutScopes();

call_user_func($column, $query);
$column($query);

$this->query->addNestedWhereQuery($query->getQuery(), $boolean);
} else {
call_user_func_array([$this->query, 'where'], func_get_args());
$this->query->where(...func_get_args());
}

return $this;
Expand Down Expand Up @@ -1228,7 +1230,7 @@ protected function callScope(callable $scope, $parameters = [])
// query as their own isolated nested where statement and avoid issues.
$originalWhereCount = count($query->wheres);

$result = call_user_func_array($scope, $parameters) ?: $this;
$result = $scope(...array_values($parameters)) ?: $this;

if ($this->shouldNestWheresForScope($query, $originalWhereCount)) {
$this->nestWheresForScope($query, $originalWhereCount);
Expand Down Expand Up @@ -1457,18 +1459,18 @@ public function __call($method, $parameters)
if (isset($this->macros[$method])) {
array_unshift($parameters, $this);

return call_user_func_array($this->macros[$method], $parameters);
return $this->macros[$method](...$parameters);
}

if (method_exists($this->model, $scope = 'scope'.ucfirst($method))) {
return $this->callScope([$this->model, $scope], $parameters);
}

if (in_array($method, $this->passthru)) {
return call_user_func_array([$this->toBase(), $method], $parameters);
return $this->toBase()->$method(...$parameters);
}

call_user_func_array([$this->query, $method], $parameters);
$this->query->$method(...$parameters);

return $this;
}
Expand Down

0 comments on commit dd3c081

Please sign in to comment.