Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[9.x] Add null typing to connection property in \Illuminate\Database\Eloquent\Factories\Factory #41418

Merged
merged 3 commits into from Mar 10, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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