Skip to content

Commit 7e674e2

Browse files
committed
De-duplicate seeder instantiation
1 parent f925658 commit 7e674e2

1 file changed

Lines changed: 9 additions & 19 deletions

File tree

system/Database/Seeder.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -127,25 +127,16 @@ public static function faker(): ?Generator
127127
*/
128128
public function call(string $class)
129129
{
130-
if (empty($class))
130+
$class = trim($class);
131+
132+
if ($class === '')
131133
{
132134
throw new InvalidArgumentException('No seeder was specified.');
133135
}
134136

135-
$path = str_replace('.php', '', $class) . '.php';
136-
137-
// If we have namespaced class, simply try to load it.
138-
if (strpos($class, '\\') !== false)
137+
if (strpos($class, '\\') === false)
139138
{
140-
/**
141-
* @var Seeder
142-
*/
143-
$seeder = new $class($this->config);
144-
}
145-
// Otherwise, try to load the class manually.
146-
else
147-
{
148-
$path = $this->seedPath . $path;
139+
$path = $this->seedPath . str_replace('.php', '', $class) . '.php';
149140

150141
if (! is_file($path))
151142
{
@@ -160,14 +151,13 @@ public function call(string $class)
160151
{
161152
require_once $path;
162153
}
163-
164-
/**
165-
* @var Seeder
166-
*/
167-
$seeder = new $class($this->config);
168154
// @codeCoverageIgnoreEnd
169155
}
170156

157+
/**
158+
* @var Seeder
159+
*/
160+
$seeder = new $class($this->config);
171161
$seeder->setSilent($this->silent)->run();
172162

173163
unset($seeder);

0 commit comments

Comments
 (0)