Skip to content

Commit

Permalink
Use coalesce equal as provided by PHP >= 8 (#41174)
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored Feb 22, 2022
1 parent e6c510d commit fc97186
Show file tree
Hide file tree
Showing 20 changed files with 35 additions and 35 deletions.
2 changes: 1 addition & 1 deletion src/Illuminate/Auth/Access/Gate.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ protected function callAfterCallbacks($user, $ability, array $arguments, $result

$afterResult = $after($user, $ability, $result, $arguments);

$result = $result ?? $afterResult;
$result ??= $afterResult;
}

return $result;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Broadcasting/BroadcastManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ public function setDefaultDriver($name)
*/
public function purge($name = null)
{
$name = $name ?? $this->getDefaultDriver();
$name ??= $this->getDefaultDriver();

unset($this->drivers[$name]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Cache/CacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ public function setDefaultDriver($name)
*/
public function forgetDriver($name = null)
{
$name = $name ?? $this->getDefaultDriver();
$name ??= $this->getDefaultDriver();

foreach ((array) $name as $cacheName) {
if (isset($this->stores[$cacheName])) {
Expand All @@ -387,7 +387,7 @@ public function forgetDriver($name = null)
*/
public function purge($name = null)
{
$name = $name ?? $this->getDefaultDriver();
$name ??= $this->getDefaultDriver();

unset($this->stores[$name]);
}
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Concerns/BuildsQueries.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ public function each(callable $callback, $count = 1000)
*/
public function chunkById($count, callable $callback, $column = null, $alias = null)
{
$column = $column ?? $this->defaultKeyName();
$column ??= $this->defaultKeyName();

$alias = $alias ?? $column;
$alias ??= $column;

$lastId = null;

Expand Down Expand Up @@ -256,9 +256,9 @@ protected function orderedLazyById($chunkSize = 1000, $column = null, $alias = n
throw new InvalidArgumentException('The chunk size should be at least 1');
}

$column = $column ?? $this->defaultKeyName();
$column ??= $this->defaultKeyName();

$alias = $alias ?? $column;
$alias ??= $column;

return LazyCollection::make(function () use ($chunkSize, $column, $alias, $descending) {
$lastId = null;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Connectors/PostgresConnector.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ protected function parseSearchPath($searchPath)
$searchPath = $matches[0];
}

$searchPath = $searchPath ?? [];
$searchPath ??= [];

array_walk($searchPath, function (&$schema) {
$schema = trim($schema, '\'"');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,7 @@ public function withAggregate($relations, $column, $function = null)
// Finally, we will make the proper column alias to the query and run this sub-select on
// the query builder. Then, we will return the builder instance back to the developer
// for further constraint chaining that needs to take place on the query as needed.
$alias = $alias ?? Str::snake(
$alias ??= Str::snake(
preg_replace('/[^[:alnum:][:space:]_]/u', '', "$name $function $column")
);

Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -934,11 +934,11 @@ public function chunkById($count, callable $callback, $column = null, $alias = n
{
$this->prepareQueryBuilder();

$column = $column ?? $this->getRelated()->qualifyColumn(
$column ??= $this->getRelated()->qualifyColumn(
$this->getRelatedKeyName()
);

$alias = $alias ?? $this->getRelatedKeyName();
$alias ??= $this->getRelatedKeyName();

return $this->query->chunkById($count, function ($results) use ($callback) {
$this->hydratePivotRelation($results->all());
Expand Down Expand Up @@ -990,11 +990,11 @@ public function lazy($chunkSize = 1000)
*/
public function lazyById($chunkSize = 1000, $column = null, $alias = null)
{
$column = $column ?? $this->getRelated()->qualifyColumn(
$column ??= $this->getRelated()->qualifyColumn(
$this->getRelatedKeyName()
);

$alias = $alias ?? $this->getRelatedKeyName();
$alias ??= $this->getRelatedKeyName();

return $this->prepareQueryBuilder()->lazyById($chunkSize, $column, $alias)->map(function ($model) {
$this->hydratePivotRelation([$model]);
Expand Down
8 changes: 4 additions & 4 deletions src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,9 +508,9 @@ public function chunk($count, callable $callback)
*/
public function chunkById($count, callable $callback, $column = null, $alias = null)
{
$column = $column ?? $this->getRelated()->getQualifiedKeyName();
$column ??= $this->getRelated()->getQualifiedKeyName();

$alias = $alias ?? $this->getRelated()->getKeyName();
$alias ??= $this->getRelated()->getKeyName();

return $this->prepareQueryBuilder()->chunkById($count, $callback, $column, $alias);
}
Expand Down Expand Up @@ -564,9 +564,9 @@ public function lazy($chunkSize = 1000)
*/
public function lazyById($chunkSize = 1000, $column = null, $alias = null)
{
$column = $column ?? $this->getRelated()->getQualifiedKeyName();
$column ??= $this->getRelated()->getQualifiedKeyName();

$alias = $alias ?? $this->getRelated()->getKeyName();
$alias ??= $this->getRelated()->getKeyName();

return $this->prepareQueryBuilder()->lazyById($chunkSize, $column, $alias);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/MySqlSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected function connectionString()
*/
protected function baseVariables(array $config)
{
$config['host'] = $config['host'] ?? '';
$config['host'] ??= '';

return [
'LARAVEL_LOAD_SOCKET' => $config['unix_socket'] ?? '',
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/PostgresBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ protected function parseSearchPath($searchPath)
$searchPath = $matches[0];
}

$searchPath = $searchPath ?? [];
$searchPath ??= [];

array_walk($searchPath, function (&$schema) {
$schema = trim($schema, '\'"');
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Schema/PostgresSchemaState.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ protected function baseDumpCommand()
*/
protected function baseVariables(array $config)
{
$config['host'] = $config['host'] ?? '';
$config['host'] ??= '';

return [
'LARAVEL_LOAD_HOST' => is_array($config['host']) ? $config['host'][0] : $config['host'],
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Filesystem/FilesystemManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ protected function get($name)
*/
protected function resolve($name, $config = null)
{
$config = $config ?? $this->getConfig($name);
$config ??= $this->getConfig($name);

if (empty($config['driver'])) {
throw new InvalidArgumentException("Disk [{$name}] does not have a configured driver.");
Expand Down Expand Up @@ -352,7 +352,7 @@ public function forgetDisk($disk)
*/
public function purge($name = null)
{
$name = $name ?? $this->getDefaultDriver();
$name ??= $this->getDefaultDriver();

unset($this->disks[$name]);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Testing/WithFaker.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function faker($locale = null)
*/
protected function makeFaker($locale = null)
{
$locale = $locale ?? config('app.faker_locale', Factory::DEFAULT_LOCALE);
$locale ??= config('app.faker_locale', Factory::DEFAULT_LOCALE);

if (isset($this->app) && $this->app->bound(Generator::class)) {
return $this->app->make(Generator::class, ['locale' => $locale]);
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Log/LogManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ protected function createEmergencyLogger()
*/
protected function resolve($name, ?array $config = null)
{
$config = $config ?? $this->configurationFor($name);
$config ??= $this->configurationFor($name);

if (is_null($config)) {
throw new InvalidArgumentException("Log [{$name}] is not defined.");
Expand Down Expand Up @@ -517,10 +517,10 @@ public function forgetChannel($driver = null)
*/
protected function parseDriver($driver)
{
$driver = $driver ?? $this->getDefaultDriver();
$driver ??= $this->getDefaultDriver();

if ($this->app->runningUnitTests()) {
$driver = $driver ?? 'null';
$driver ??= 'null';
}

return $driver;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Mail/Mailable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ protected function renderForAssertions()
$text = $view[1];
}

$text = $text ?? $view['text'] ?? '';
$text ??= $view['text'] ?? '';

if (! empty($text) && ! $text instanceof Htmlable) {
$text = Container::getInstance()->make('mailer')->render(
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Console/ControllerMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function getStub()
$stub = str_replace('.stub', '.api.stub', $stub);
}

$stub = $stub ?? '/stubs/controller.plain.stub';
$stub ??= '/stubs/controller.plain.stub';

return $this->resolveStubPath($stub);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Routing/Route.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,7 @@ public function getPrefix()
*/
public function prefix($prefix)
{
$prefix = $prefix ?? '';
$prefix ??= '';

$this->updatePrefixOnAction($prefix);

Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Support/MultipleInstanceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ protected function callCustomCreator(array $config)
*/
public function forgetInstance($name = null)
{
$name = $name ?? $this->getDefaultInstance();
$name ??= $this->getDefaultInstance();

foreach ((array) $name as $instanceName) {
if (isset($this->instances[$instanceName])) {
Expand All @@ -158,7 +158,7 @@ public function forgetInstance($name = null)
*/
public function purge($name = null)
{
$name = $name ?? $this->getDefaultInstance();
$name ??= $this->getDefaultInstance();

unset($this->instances[$name]);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -866,7 +866,7 @@ public function validateUnique($attribute, $value, $parameters)
*/
protected function getUniqueIds($idColumn, $parameters)
{
$idColumn = $idColumn ?? $parameters[3] ?? 'id';
$idColumn ??= $parameters[3] ?? 'id';

return [$idColumn, $this->prepareUniqueId($parameters[2])];
}
Expand Down Expand Up @@ -923,7 +923,7 @@ public function parseTable($table)
$model = new $table;

$table = $model->getTable();
$connection = $connection ?? $model->getConnectionName();
$connection ??= $model->getConnectionName();

if (str_contains($table, '.') && Str::startsWith($table, $connection)) {
$connection = null;
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 @@ -524,7 +524,7 @@ protected function compileStatement($match)
*/
protected function callCustomDirective($name, $value)
{
$value = $value ?? '';
$value ??= '';

if (str_starts_with($value, '(') && str_ends_with($value, ')')) {
$value = Str::substr($value, 1, -1);
Expand Down

0 comments on commit fc97186

Please sign in to comment.