From bf000bce43f59144594ab30c46280b929d365151 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Tue, 22 Feb 2022 15:00:18 +0100 Subject: [PATCH] Use coalesce equal as provided by PHP >= 8 --- src/Illuminate/Auth/Access/Gate.php | 2 +- src/Illuminate/Broadcasting/BroadcastManager.php | 2 +- src/Illuminate/Cache/CacheManager.php | 4 ++-- src/Illuminate/Database/Concerns/BuildsQueries.php | 8 ++++---- src/Illuminate/Database/Connectors/PostgresConnector.php | 2 +- .../Database/Eloquent/Concerns/QueriesRelationships.php | 2 +- .../Database/Eloquent/Relations/BelongsToMany.php | 8 ++++---- .../Database/Eloquent/Relations/HasManyThrough.php | 8 ++++---- src/Illuminate/Database/Schema/MySqlSchemaState.php | 2 +- src/Illuminate/Database/Schema/PostgresBuilder.php | 2 +- src/Illuminate/Database/Schema/PostgresSchemaState.php | 2 +- src/Illuminate/Filesystem/FilesystemManager.php | 4 ++-- src/Illuminate/Foundation/Testing/WithFaker.php | 2 +- src/Illuminate/Log/LogManager.php | 6 +++--- src/Illuminate/Mail/Mailable.php | 2 +- src/Illuminate/Routing/Console/ControllerMakeCommand.php | 2 +- src/Illuminate/Routing/Route.php | 2 +- src/Illuminate/Support/MultipleInstanceManager.php | 4 ++-- .../Validation/Concerns/ValidatesAttributes.php | 4 ++-- src/Illuminate/View/Compilers/BladeCompiler.php | 2 +- 20 files changed, 35 insertions(+), 35 deletions(-) diff --git a/src/Illuminate/Auth/Access/Gate.php b/src/Illuminate/Auth/Access/Gate.php index 561f6d7a8c82..145c1c306e9a 100644 --- a/src/Illuminate/Auth/Access/Gate.php +++ b/src/Illuminate/Auth/Access/Gate.php @@ -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; diff --git a/src/Illuminate/Broadcasting/BroadcastManager.php b/src/Illuminate/Broadcasting/BroadcastManager.php index eecc32c107cd..f9ad1b23f359 100644 --- a/src/Illuminate/Broadcasting/BroadcastManager.php +++ b/src/Illuminate/Broadcasting/BroadcastManager.php @@ -346,7 +346,7 @@ public function setDefaultDriver($name) */ public function purge($name = null) { - $name = $name ?? $this->getDefaultDriver(); + $name ??= $this->getDefaultDriver(); unset($this->drivers[$name]); } diff --git a/src/Illuminate/Cache/CacheManager.php b/src/Illuminate/Cache/CacheManager.php index fbd7011289f0..fb783e2c628a 100755 --- a/src/Illuminate/Cache/CacheManager.php +++ b/src/Illuminate/Cache/CacheManager.php @@ -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])) { @@ -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]); } diff --git a/src/Illuminate/Database/Concerns/BuildsQueries.php b/src/Illuminate/Database/Concerns/BuildsQueries.php index c47c582e1922..27034596b980 100644 --- a/src/Illuminate/Database/Concerns/BuildsQueries.php +++ b/src/Illuminate/Database/Concerns/BuildsQueries.php @@ -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; @@ -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; diff --git a/src/Illuminate/Database/Connectors/PostgresConnector.php b/src/Illuminate/Database/Connectors/PostgresConnector.php index 29fe16662f9a..f25ad0a6b38f 100755 --- a/src/Illuminate/Database/Connectors/PostgresConnector.php +++ b/src/Illuminate/Database/Connectors/PostgresConnector.php @@ -132,7 +132,7 @@ protected function parseSearchPath($searchPath) $searchPath = $matches[0]; } - $searchPath = $searchPath ?? []; + $searchPath ??= []; array_walk($searchPath, function (&$schema) { $schema = trim($schema, '\'"'); diff --git a/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php b/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php index 2cb68ff97a9d..8b6f9b4ec3ab 100644 --- a/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php +++ b/src/Illuminate/Database/Eloquent/Concerns/QueriesRelationships.php @@ -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") ); diff --git a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php index da4d1a8aa6bf..fd62627fbd49 100755 --- a/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php +++ b/src/Illuminate/Database/Eloquent/Relations/BelongsToMany.php @@ -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()); @@ -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]); diff --git a/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php b/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php index 14baa48c03a6..74326957364c 100644 --- a/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php +++ b/src/Illuminate/Database/Eloquent/Relations/HasManyThrough.php @@ -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); } @@ -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); } diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index ab55a7bc4bc3..add5aa61d19d 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -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'] ?? '', diff --git a/src/Illuminate/Database/Schema/PostgresBuilder.php b/src/Illuminate/Database/Schema/PostgresBuilder.php index 19b80c12db2e..6a6aa1602b75 100755 --- a/src/Illuminate/Database/Schema/PostgresBuilder.php +++ b/src/Illuminate/Database/Schema/PostgresBuilder.php @@ -241,7 +241,7 @@ protected function parseSearchPath($searchPath) $searchPath = $matches[0]; } - $searchPath = $searchPath ?? []; + $searchPath ??= []; array_walk($searchPath, function (&$schema) { $schema = trim($schema, '\'"'); diff --git a/src/Illuminate/Database/Schema/PostgresSchemaState.php b/src/Illuminate/Database/Schema/PostgresSchemaState.php index 884d3ec22cfe..b6d4273ffafa 100644 --- a/src/Illuminate/Database/Schema/PostgresSchemaState.php +++ b/src/Illuminate/Database/Schema/PostgresSchemaState.php @@ -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'], diff --git a/src/Illuminate/Filesystem/FilesystemManager.php b/src/Illuminate/Filesystem/FilesystemManager.php index 7cf963bd580f..cd2e1dd5532f 100644 --- a/src/Illuminate/Filesystem/FilesystemManager.php +++ b/src/Illuminate/Filesystem/FilesystemManager.php @@ -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."); @@ -352,7 +352,7 @@ public function forgetDisk($disk) */ public function purge($name = null) { - $name = $name ?? $this->getDefaultDriver(); + $name ??= $this->getDefaultDriver(); unset($this->disks[$name]); } diff --git a/src/Illuminate/Foundation/Testing/WithFaker.php b/src/Illuminate/Foundation/Testing/WithFaker.php index cd276fbd4eb0..202a63e8c43b 100644 --- a/src/Illuminate/Foundation/Testing/WithFaker.php +++ b/src/Illuminate/Foundation/Testing/WithFaker.php @@ -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]); diff --git a/src/Illuminate/Log/LogManager.php b/src/Illuminate/Log/LogManager.php index 99e88358b1f4..751b5e58b275 100644 --- a/src/Illuminate/Log/LogManager.php +++ b/src/Illuminate/Log/LogManager.php @@ -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."); @@ -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; diff --git a/src/Illuminate/Mail/Mailable.php b/src/Illuminate/Mail/Mailable.php index 01de322546f9..7427ac7ccb72 100644 --- a/src/Illuminate/Mail/Mailable.php +++ b/src/Illuminate/Mail/Mailable.php @@ -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( diff --git a/src/Illuminate/Routing/Console/ControllerMakeCommand.php b/src/Illuminate/Routing/Console/ControllerMakeCommand.php index 6768692dac1a..988c9ba539ad 100755 --- a/src/Illuminate/Routing/Console/ControllerMakeCommand.php +++ b/src/Illuminate/Routing/Console/ControllerMakeCommand.php @@ -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); } diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php index fc30acb65ace..53a1f617f91e 100755 --- a/src/Illuminate/Routing/Route.php +++ b/src/Illuminate/Routing/Route.php @@ -780,7 +780,7 @@ public function getPrefix() */ public function prefix($prefix) { - $prefix = $prefix ?? ''; + $prefix ??= ''; $this->updatePrefixOnAction($prefix); diff --git a/src/Illuminate/Support/MultipleInstanceManager.php b/src/Illuminate/Support/MultipleInstanceManager.php index 97cee33af201..8544bdf71b34 100644 --- a/src/Illuminate/Support/MultipleInstanceManager.php +++ b/src/Illuminate/Support/MultipleInstanceManager.php @@ -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])) { @@ -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]); } diff --git a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php index dfa74cdfb476..156af464e113 100644 --- a/src/Illuminate/Validation/Concerns/ValidatesAttributes.php +++ b/src/Illuminate/Validation/Concerns/ValidatesAttributes.php @@ -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])]; } @@ -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; diff --git a/src/Illuminate/View/Compilers/BladeCompiler.php b/src/Illuminate/View/Compilers/BladeCompiler.php index 1e96b17703d2..85bf5523bab4 100644 --- a/src/Illuminate/View/Compilers/BladeCompiler.php +++ b/src/Illuminate/View/Compilers/BladeCompiler.php @@ -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);