Skip to content

Commit

Permalink
Early return in Factory::modelName() (#53912)
Browse files Browse the repository at this point in the history
to avoid possibliy defining a function that will not be used
  • Loading branch information
shaedrich authored Dec 16, 2024
1 parent a306193 commit 603b0cf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Database/Eloquent/Factories/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -813,6 +813,10 @@ public function newModel(array $attributes = [])
*/
public function modelName()
{
if ($this->model !== null) {
return $this->model;
}

$resolver = static::$modelNameResolver ?? function (self $factory) {
$namespacedFactoryBasename = Str::replaceLast(
'Factory', '', Str::replaceFirst(static::$namespace, '', get_class($factory))
Expand All @@ -827,7 +831,7 @@ public function modelName()
: $appNamespace.$factoryBasename;
};

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

/**
Expand Down

0 comments on commit 603b0cf

Please sign in to comment.