Skip to content

Commit 72cb14a

Browse files
Refactor Faker class and add new methods for seeding and instance creation
1 parent 423e279 commit 72cb14a

File tree

1 file changed

+37
-1
lines changed

1 file changed

+37
-1
lines changed

src/Utils/Faker.php

+37-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@ public function __construct(
3232
protected ?FakerMediaLocal $mediaLocal = null,
3333
protected ?FakerMediaDownloader $mediaDownloader = null,
3434
protected ?FakerJson $json = null,
35-
) {}
35+
) {
36+
}
3637

38+
/**
39+
* Clear `storage/app/public` and `storage/app/download` directories before seeding.
40+
*/
3741
public static function beforeSeed(): bool
3842
{
3943
$paths = [
@@ -50,12 +54,18 @@ public static function beforeSeed(): bool
5054
return true;
5155
}
5256

57+
/**
58+
* Run `scout:fresh` and `media:clean` commands after seeding.
59+
*/
5360
public static function afterSeed(): void
5461
{
5562
Artisan::call(ScoutFreshCommand::class);
5663
Artisan::call(MediaCleanCommand::class, ['--force' => true]);
5764
}
5865

66+
/**
67+
* Create a new instance of the service.
68+
*/
5969
public static function make(string|\UnitEnum|null $mediaPath = null): self
6070
{
6171
$generator = \Faker\Factory::create();
@@ -70,6 +80,9 @@ public static function make(string|\UnitEnum|null $mediaPath = null): self
7080
return $service;
7181
}
7282

83+
/**
84+
* Create a new instance of the service without search.
85+
*/
7386
public static function noSearch(string $model, Closure $closure): mixed
7487
{
7588
$item = ClassParserItem::make($model);
@@ -81,6 +94,9 @@ public static function noSearch(string $model, Closure $closure): mixed
8194
return $model::withoutSyncingToSearch(fn () => $closure());
8295
}
8396

97+
/**
98+
* `text()` and `richText()` factories.
99+
*/
84100
public function useText(?FakerTextEnum $type = null): self
85101
{
86102
$this->text = $this->setFakerText($type);
@@ -89,21 +105,41 @@ public function useText(?FakerTextEnum $type = null): self
89105
return $this;
90106
}
91107

108+
/**
109+
* Get the generator instance.
110+
*/
92111
public function generator(): Generator
93112
{
94113
return $this->generator;
95114
}
96115

116+
/**
117+
* @deprecated Use `generator()` method instead.
118+
*/
119+
public function faker(): Generator
120+
{
121+
return $this->generator();
122+
}
123+
124+
/**
125+
* Get the text factory instance.
126+
*/
97127
public function text(): FakerText
98128
{
99129
return $this->text;
100130
}
101131

132+
/**
133+
* Get the rich text factory instance.
134+
*/
102135
public function richText(): FakerRichText
103136
{
104137
return $this->richText;
105138
}
106139

140+
/**
141+
* Get the date time factory instance.
142+
*/
107143
public function dateTime(): FakerDateTime
108144
{
109145
return $this->dateTime;

0 commit comments

Comments
 (0)