Skip to content

Commit

Permalink
[11.x] remove temporary variables (#53810)
Browse files Browse the repository at this point in the history
* remove simple temporary variables

the declared variable is only used once. inlining does not decrease readability.

my guess is it was originally written this way *before* we had arrow functions, and could inherit the outer `$this` scope.

also minor formatting update to use our new multiline chaining standard

* revert

* inline some more simple variables

also put each argument on separate line for multiline for better git diffs

* remove more temporary variables

a couple more real simple ones
  • Loading branch information
browner12 authored Dec 10, 2024
1 parent f278399 commit a3b99f1
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 29 deletions.
12 changes: 7 additions & 5 deletions src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,14 @@ protected function formatAbilityToMethod($ability)
*/
public function forUser($user)
{
$callback = fn () => $user;

return new static(
$this->container, $callback, $this->abilities,
$this->policies, $this->beforeCallbacks, $this->afterCallbacks,
$this->guessPolicyNamesUsingCallback
$this->container,
fn () => $user,
$this->abilities,
$this->policies,
$this->beforeCallbacks,
$this->afterCallbacks,
$this->guessPolicyNamesUsingCallback,
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Auth/AuthManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,9 @@ protected function callCustomCreator($name, array $config)
*/
public function createSessionDriver($name, $config)
{
$provider = $this->createUserProvider($config['provider'] ?? null);

$guard = new SessionGuard(
$name,
$provider,
$this->createUserProvider($config['provider'] ?? null),
$this->app['session.store'],
rehashOnLogin: $this->app['config']->get('hashing.rehash_on_login', true),
);
Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Auth/CreatesUserProviders.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,11 @@ protected function getProviderConfiguration($provider)
*/
protected function createDatabaseProvider($config)
{
$connection = $this->app['db']->connection($config['connection'] ?? null);

return new DatabaseUserProvider($connection, $this->app['hash'], $config['table']);
return new DatabaseUserProvider(
$this->app['db']->connection($config['connection'] ?? null),
$this->app['hash'],
$config['table'],
);
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Foundation/Concerns/ResolvesDumpSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,13 +165,11 @@ protected function resolveSourceHref($file, $line)
$file = str_replace($this->basePath, $basePath, $file);
}

$href = str_replace(
return str_replace(
['{file}', '{line}'],
[$file, is_null($line) ? 1 : $line],
$href,
);

return $href;
}

/**
Expand Down
10 changes: 4 additions & 6 deletions src/Illuminate/Http/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -224,9 +224,8 @@ public function segments()
*/
public function is(...$patterns)
{
$path = $this->decodedPath();

return (new Collection($patterns))->contains(fn ($pattern) => Str::is($pattern, $path));
return (new Collection($patterns))
->contains(fn ($pattern) => Str::is($pattern, $this->decodedPath()));
}

/**
Expand All @@ -248,9 +247,8 @@ public function routeIs(...$patterns)
*/
public function fullUrlIs(...$patterns)
{
$url = $this->fullUrl();

return (new Collection($patterns))->contains(fn ($pattern) => Str::is($pattern, $url));
return (new Collection($patterns))
->contains(fn ($pattern) => Str::is($pattern, $this->fullUrl()));
}

/**
Expand Down
8 changes: 5 additions & 3 deletions src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -320,10 +320,12 @@ protected function isReservedButExpired($query)
*/
protected function marshalJob($queue, $job)
{
$job = $this->markJobAsReserved($job);

return new DatabaseJob(
$this->container, $this, $job, $this->connectionName, $queue
$this->container,
$this,
$this->markJobAsReserved($job),
$this->connectionName,
$queue,
);
}

Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Routing/Console/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ protected function buildClass($name)
$replace["use {$rootNamespace}Http\Controllers\Controller;\n"] = '';
}

$class = str_replace(
return str_replace(
array_keys($replace), array_values($replace), parent::buildClass($name)
);

return $class;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ protected function setUp(): void

private function __reflectAndSetupAccessibleForProtectedTraitMethod($methodName)
{
$migrateFreshUsingReflection = new ReflectionMethod(
return new ReflectionMethod(
get_class($this->traitObject),
$methodName
);

return $migrateFreshUsingReflection;
}

public function testMigrateFreshUsingDefault(): void
Expand Down

0 comments on commit a3b99f1

Please sign in to comment.