From 432f9d688d4cfbdae199bc406ec1e78c92f99725 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Thu, 10 Mar 2022 09:40:08 +0100 Subject: [PATCH 1/3] Add null typing to nullable properties in \Illuminate\Database\Eloquent\Factories\Factory --- .../Database/Eloquent/Factories/Factory.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Factories/Factory.php b/src/Illuminate/Database/Eloquent/Factories/Factory.php index 43d37719dfda..df89d86cb2ef 100644 --- a/src/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/src/Illuminate/Database/Eloquent/Factories/Factory.php @@ -41,42 +41,42 @@ abstract class Factory /** * The state transformations that will be applied to the model. * - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection|null */ protected $states; /** * The parent relationships that will be applied to the model. * - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection|null */ protected $has; /** * The child relationships that will be applied to the model. * - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection|null */ protected $for; /** * The "after making" callbacks that will be applied to the model. * - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection|null */ protected $afterMaking; /** * The "after creating" callbacks that will be applied to the model. * - * @var \Illuminate\Support\Collection + * @var \Illuminate\Support\Collection|null */ protected $afterCreating; /** * The name of the database connection that will be used to create the models. * - * @var string + * @var string|null */ protected $connection; From 9ed535fda3940005239c968a9955e3861dd39b95 Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Thu, 10 Mar 2022 10:17:59 +0100 Subject: [PATCH 2/3] Restore docstring on practically non-null properties in \Illuminate\Database\Eloquent\Factories\Factory --- src/Illuminate/Database/Eloquent/Factories/Factory.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Factories/Factory.php b/src/Illuminate/Database/Eloquent/Factories/Factory.php index df89d86cb2ef..068a845155ff 100644 --- a/src/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/src/Illuminate/Database/Eloquent/Factories/Factory.php @@ -41,35 +41,35 @@ abstract class Factory /** * The state transformations that will be applied to the model. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $states; /** * The parent relationships that will be applied to the model. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $has; /** * The child relationships that will be applied to the model. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $for; /** * The "after making" callbacks that will be applied to the model. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $afterMaking; /** * The "after creating" callbacks that will be applied to the model. * - * @var \Illuminate\Support\Collection|null + * @var \Illuminate\Support\Collection */ protected $afterCreating; From 1f57ae9e26eb5a8648d11a084f2cdbfdeaa4b18a Mon Sep 17 00:00:00 2001 From: Jesper Noordsij Date: Thu, 10 Mar 2022 10:20:05 +0100 Subject: [PATCH 3/3] Switch to null coalescing operator in \Illuminate\Database\Eloquent\Factories\Factory --- .../Database/Eloquent/Factories/Factory.php | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Illuminate/Database/Eloquent/Factories/Factory.php b/src/Illuminate/Database/Eloquent/Factories/Factory.php index 068a845155ff..e1e4ef4cf90c 100644 --- a/src/Illuminate/Database/Eloquent/Factories/Factory.php +++ b/src/Illuminate/Database/Eloquent/Factories/Factory.php @@ -129,11 +129,11 @@ public function __construct($count = null, $connection = null) { $this->count = $count; - $this->states = $states ?: new Collection; - $this->has = $has ?: new Collection; - $this->for = $for ?: new Collection; - $this->afterMaking = $afterMaking ?: new Collection; - $this->afterCreating = $afterCreating ?: new Collection; + $this->states = $states ?? new Collection; + $this->has = $has ?? new Collection; + $this->for = $for ?? new Collection; + $this->afterMaking = $afterMaking ?? new Collection; + $this->afterCreating = $afterCreating ?? new Collection; $this->connection = $connection; $this->faker = $this->withFaker(); } @@ -516,7 +516,7 @@ public function has(self $factory, $relationship = null) { return $this->newInstance([ 'has' => $this->has->concat([new Relationship( - $factory, $relationship ?: $this->guessRelationship($factory->modelName()) + $factory, $relationship ?? $this->guessRelationship($factory->modelName()) )]), ]); } @@ -548,7 +548,7 @@ public function hasAttached($factory, $pivot = [], $relationship = null) 'has' => $this->has->concat([new BelongsToManyRelationship( $factory, $pivot, - $relationship ?: Str::camel(Str::plural(class_basename( + $relationship ?? Str::camel(Str::plural(class_basename( $factory instanceof Factory ? $factory->modelName() : Collection::wrap($factory)->first() @@ -568,7 +568,7 @@ public function for($factory, $relationship = null) { return $this->newInstance(['for' => $this->for->concat([new BelongsToRelationship( $factory, - $relationship ?: Str::camel(class_basename( + $relationship ?? Str::camel(class_basename( $factory instanceof Factory ? $factory->modelName() : $factory )) )])]); @@ -688,7 +688,7 @@ public function newModel(array $attributes = []) */ public function modelName() { - $resolver = static::$modelNameResolver ?: function (self $factory) { + $resolver = static::$modelNameResolver ?? function (self $factory) { $namespacedFactoryBasename = Str::replaceLast( 'Factory', '', Str::replaceFirst(static::$namespace, '', get_class($factory)) ); @@ -702,7 +702,7 @@ public function modelName() : $appNamespace.$factoryBasename; }; - return $this->model ?: $resolver($this); + return $this->model ?? $resolver($this); } /** @@ -769,7 +769,7 @@ protected function withFaker() */ public static function resolveFactoryName(string $modelName) { - $resolver = static::$factoryNameResolver ?: function (string $modelName) { + $resolver = static::$factoryNameResolver ?? function (string $modelName) { $appNamespace = static::appNamespace(); $modelName = Str::startsWith($modelName, $appNamespace.'Models\\') @@ -820,7 +820,7 @@ public function __call($method, $parameters) $relatedModel = get_class($this->newModel()->{$relationship}()->getRelated()); if (method_exists($relatedModel, 'newFactory')) { - $factory = $relatedModel::newFactory() ?: static::factoryForModel($relatedModel); + $factory = $relatedModel::newFactory() ?? static::factoryForModel($relatedModel); } else { $factory = static::factoryForModel($relatedModel); }