Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[6.x] Convert call_user_func where appropriate to native calls #29932

Merged
merged 1 commit into from
Sep 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/Illuminate/Console/ConfirmableTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function confirmToProceed($warning = 'Application In Production!', $callb
{
$callback = is_null($callback) ? $this->getDefaultConfirmCallback() : $callback;

$shouldConfirm = $callback instanceof Closure ? call_user_func($callback) : $callback;
$shouldConfirm = $callback instanceof Closure ? $callback() : $callback;

if ($shouldConfirm) {
if ($this->hasOption('force') && $this->option('force')) {
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ public function firstOr($columns = ['*'], Closure $callback = null)
return $model;
}

return call_user_func($callback);
return $callback();
}

/**
Expand Down
5 changes: 1 addition & 4 deletions src/Illuminate/Database/Eloquent/FactoryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,7 @@ protected function stateAttributes($state, array $attributes)
return $stateAttributes;
}

return call_user_func(
$stateAttributes,
$this->faker, $attributes
);
return $stateAttributes($this->faker, $attributes);
Copy link
Member

@crynobone crynobone Sep 11, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here it's checking for is_callable(), if you give [$object, 'bar'] it going to return true, but AFAIK it not possible to do [$object, 'bar'](...)

Tested, seem to work.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeh, you can call callables like that. The two cases I didn't convert are ones with assignments to the variable holding the callable within the call_user_func parameters, and callables which were properties of classes.

}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ public static function withoutTouchingOn(array $models, callable $callback)
static::$ignoreOnTouch = array_values(array_merge(static::$ignoreOnTouch, $models));

try {
call_user_func($callback);
$callback();
} finally {
static::$ignoreOnTouch = array_values(array_diff(static::$ignoreOnTouch, $models));
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Relations/Relation.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public static function noConstraints(Closure $callback)
// off of the bindings, leaving only the constraints that the developers put
// as "extra" on the relationships, and not original relation constraints.
try {
return call_user_func($callback);
return $callback();
} finally {
static::$constraints = $previous;
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Migrations/MigrationCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected function getPath($name, $path)
protected function firePostCreateHooks($table)
{
foreach ($this->postCreate as $callback) {
call_user_func($callback, $table);
$callback($table);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ public function join($table, $first, $operator = null, $second = null, $type = '
// is trying to build a join with a complex "on" clause containing more than
// one condition, so we'll add the join and call a Closure with the query.
if ($first instanceof Closure) {
call_user_func($first, $join);
$first($join);

$this->joins[] = $join;

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -864,7 +864,7 @@ public function booted($callback)
protected function fireAppCallbacks(array $callbacks)
{
foreach ($callbacks as $callback) {
call_user_func($callback, $this);
$callback($this);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/EnvironmentDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function detect(Closure $callback, $consoleArgs = null)
*/
protected function detectWebEnvironment(Closure $callback)
{
return call_user_func($callback);
return $callback();
}

/**
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Foundation/Testing/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ protected function setUp(): void
$this->setUpTraits();

foreach ($this->afterApplicationCreatedCallbacks as $callback) {
call_user_func($callback);
$callback();
}

Facade::clearResolvedInstances();
Expand Down Expand Up @@ -206,7 +206,7 @@ public function afterApplicationCreated(callable $callback)
$this->afterApplicationCreatedCallbacks[] = $callback;

if ($this->setUpHasRun) {
call_user_func($callback);
$callback();
}
}

Expand All @@ -230,7 +230,7 @@ protected function callBeforeApplicationDestroyedCallbacks()
{
foreach ($this->beforeApplicationDestroyedCallbacks as $callback) {
try {
call_user_func($callback);
$callback();
} catch (Throwable $e) {
if (! $this->callbackException) {
$this->callbackException = $e;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ public function send($view, array $data = [], $callback = null)
// Once we have retrieved the view content for the e-mail we will set the body
// of this message using the HTML type, which will provide a simple wrapper
// to creating view based emails that are able to receive arrays of data.
call_user_func($callback, $message);
$callback($message);

$this->addContent($message, $view, $plain, $raw, $data);

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Redis/RedisManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ protected function connector()
$customCreator = $this->customCreators[$this->driver] ?? null;

if ($customCreator) {
return call_user_func($customCreator);
return $customCreator();
}

switch ($this->driver) {
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Routing/RouteBinding.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ protected static function createClassBinding($container, $binding)

$callable = [$container->make($class), $method];

return call_user_func($callable, $value, $route);
return $callable($value, $route);
};
}

Expand Down Expand Up @@ -73,7 +73,7 @@ public static function forModel($container, $class, $callback = null)
// what we should do when the model is not found. This just gives these
// developer a little greater flexibility to decide what will happen.
if ($callback instanceof Closure) {
return call_user_func($callback, $value);
return $callback($value);
}

throw (new ModelNotFoundException)->setModel($class);
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Arr.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public static function first($array, callable $callback = null, $default = null)
}

foreach ($array as $key => $value) {
if (call_user_func($callback, $value, $key)) {
if ($callback($value, $key)) {
return $value;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ public function search($value, $strict = false)
}

foreach ($this->items as $key => $item) {
if (call_user_func($value, $item, $key)) {
if ($value($item, $key)) {
return $key;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/Pluralizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,8 @@ protected static function matchCase($value, $comparison)
$functions = ['mb_strtolower', 'mb_strtoupper', 'ucfirst', 'ucwords'];

foreach ($functions as $function) {
if (call_user_func($function, $comparison) === $comparison) {
return call_user_func($function, $value);
if ($function($comparison) === $comparison) {
return $function($value);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Validation/Validator.php
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ public function passes()
// fire them off. This gives the callbacks a chance to perform all kinds
// of other validation that needs to get wrapped up in this operation.
foreach ($this->after as $after) {
call_user_func($after);
$after();
}

return $this->messages->isEmpty();
Expand Down Expand Up @@ -870,7 +870,7 @@ public function sometimes($attribute, $rules, callable $callback)
{
$payload = new Fluent($this->getData());

if (call_user_func($callback, $payload)) {
if ($callback($payload)) {
foreach ((array) $attribute as $key) {
$this->addRules([$key => $rules]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/Compilers/BladeCompiler.php
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ protected function parseToken($token)
protected function compileExtensions($value)
{
foreach ($this->extensions as $compiler) {
$value = call_user_func($compiler, $value, $this);
$value = $compiler($value, $this);
}

return $value;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/View.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public function render(callable $callback = null)
try {
$contents = $this->renderContents();

$response = isset($callback) ? call_user_func($callback, $this, $contents) : null;
$response = isset($callback) ? $callback($this, $contents) : null;

// Once we have the contents of the view, we will flush the sections if we are
// done rendering all views so that there is nothing left hanging over when
Expand Down