Skip to content

Commit

Permalink
[9.x] Add null typing to connection property in \Illuminate\Database\…
Browse files Browse the repository at this point in the history
…Eloquent\Factories\Factory (#41418)

* Add null typing to nullable properties in \Illuminate\Database\Eloquent\Factories\Factory

* Restore docstring on practically non-null properties in \Illuminate\Database\Eloquent\Factories\Factory

* Switch to null coalescing operator in \Illuminate\Database\Eloquent\Factories\Factory
  • Loading branch information
jnoordsij committed Mar 10, 2022
1 parent f20b074 commit c3195b3
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/Illuminate/Database/Eloquent/Factories/Factory.php
Expand Up @@ -76,7 +76,7 @@ abstract class Factory
/**
* The name of the database connection that will be used to create the models.
*
* @var string
* @var string|null
*/
protected $connection;

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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())
)]),
]);
}
Expand Down Expand Up @@ -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()
Expand All @@ -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
))
)])]);
Expand Down Expand Up @@ -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))
);
Expand All @@ -702,7 +702,7 @@ public function modelName()
: $appNamespace.$factoryBasename;
};

return $this->model ?: $resolver($this);
return $this->model ?? $resolver($this);
}

/**
Expand Down Expand Up @@ -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\\')
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit c3195b3

Please sign in to comment.