1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use Illuminate\Database\Seeder; |
4
|
|
|
use App\Models\Manager; |
5
|
|
|
use App\Models\User; |
6
|
|
|
use App\Models\JobPoster; |
7
|
|
|
use App\Models\Applicant; |
8
|
|
|
use App\Models\JobApplication; |
9
|
|
|
use App\Models\Reference; |
10
|
|
|
use App\Models\Assessment; |
11
|
|
|
|
12
|
|
|
class DevSeeder extends Seeder // phpcs:ignore |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* This seeder uses this email for an admin user. |
16
|
|
|
* Note: all seeded users have 'password' for a password. |
17
|
|
|
* |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $adminEmail = '[email protected]'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* This seeder connects all manager objects to this user. |
24
|
|
|
* Note: all seeded users have 'password' for a password. |
25
|
|
|
* |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $managerEmail = '[email protected]'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* This seeder attaches all applicant objects to this user. |
32
|
|
|
* Note: all seeded users have 'password' for a password. |
33
|
|
|
* |
34
|
|
|
* @var string |
35
|
|
|
*/ |
36
|
|
|
protected $applicantEmail = '[email protected]'; |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* Run the database seeds. |
42
|
|
|
* |
43
|
|
|
* @return void |
44
|
|
|
*/ |
45
|
|
|
public function run() : void |
46
|
|
|
{ |
47
|
|
|
$adminUser = User::where('email', $this->adminEmail)->first(); |
48
|
|
|
if ($adminUser === null) { |
49
|
|
|
$adminUser = factory(User::class)->states('admin')->create(['email' => $this->adminEmail]); |
|
|
|
|
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
$managerUser = User::where('email', $this->managerEmail)->first(); |
53
|
|
|
// Create the test manager if it does not exist yet |
54
|
|
View Code Duplication |
if ($managerUser === null) { |
|
|
|
|
55
|
|
|
$managerUser = factory(User::class)->states('manager')->create(['email' => $this->managerEmail]); |
56
|
|
|
$managerUser->manager()->save(factory(Manager::class)->create([ |
57
|
|
|
'user_id' => $managerUser->id |
58
|
|
|
])); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
factory(JobPoster::class, 3)->states('published')->create([ |
62
|
|
|
'manager_id' => $managerUser->manager->id |
63
|
|
View Code Duplication |
])->each(function ($job) : void { |
|
|
|
|
64
|
|
|
$job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
65
|
|
|
'job_poster_id' => $job->id |
66
|
|
|
]); |
67
|
|
|
//Then create one application with a priority user |
68
|
|
|
$job->job_applications()->save(factory(JobApplication::class)->create([ |
69
|
|
|
'job_poster_id' => $job->id, |
70
|
|
|
'applicant_id' => factory(Applicant::class)->create([ |
71
|
|
|
'user_id' => factory(User::class)->states('priority')->create()->id |
72
|
|
|
])->id |
73
|
|
|
])); |
74
|
|
|
}); |
75
|
|
|
factory(JobPoster::class, 3)->states('closed')->create([ |
76
|
|
|
'manager_id' => $managerUser->manager->id |
77
|
|
View Code Duplication |
])->each(function ($job) : void { |
|
|
|
|
78
|
|
|
$job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
79
|
|
|
'job_poster_id' => $job->id |
80
|
|
|
]); |
81
|
|
|
//Then create one application with a priority user |
82
|
|
|
$job->job_applications()->save(factory(JobApplication::class)->create([ |
83
|
|
|
'job_poster_id' => $job->id, |
84
|
|
|
'applicant_id' => factory(Applicant::class)->create([ |
85
|
|
|
'user_id' => factory(User::class)->state('priority')->create()->id |
86
|
|
|
])->id |
87
|
|
|
])); |
88
|
|
|
}); |
89
|
|
|
factory(JobPoster::class, 3)->states('draft')->create([ |
90
|
|
|
'manager_id' => $managerUser->manager->id |
91
|
|
|
]); |
92
|
|
|
factory(JobPoster::class, 3)->states('review_requested')->create([ |
93
|
|
|
'manager_id' => $managerUser->manager->id |
94
|
|
|
]); |
95
|
|
|
|
96
|
|
|
// Create a Job Poster with an Assessment Plan |
97
|
|
|
$jobWithAssessment = factory(JobPoster::class)->states('draft')->create([ |
98
|
|
|
'manager_id' => $managerUser->manager->id, |
99
|
|
|
]); |
100
|
|
|
foreach ($jobWithAssessment->criteria as $criterion) { |
101
|
|
|
// Create an assessment for each criterion |
102
|
|
|
factory(Assessment::class)->states('withRatingGuide')->create([ |
103
|
|
|
'criterion_id' => $criterion->id, |
104
|
|
|
]); |
105
|
|
|
}; |
106
|
|
|
|
107
|
|
|
$applicantUser = User::where('email', $this->applicantEmail)->first(); |
108
|
|
View Code Duplication |
if ($applicantUser === null) { |
|
|
|
|
109
|
|
|
$applicantUser = factory(User::class)->states('applicant')->create([ |
110
|
|
|
'email' => $this->applicantEmail |
111
|
|
|
]); |
112
|
|
|
$applicantUser->applicant()->save(factory(Applicant::class)->create([ |
113
|
|
|
'user_id' => $applicantUser->id |
114
|
|
|
])); |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// Add to application profile |
118
|
|
|
$applicantUser->applicant->references()->saveMany(factory(Reference::class, 3)->create([ |
119
|
|
|
'applicant_id' => $applicantUser->applicant->id |
120
|
|
|
])); |
121
|
|
|
|
122
|
|
|
// Create several applications for test user. |
123
|
|
|
$applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 3)->create([ |
124
|
|
|
'applicant_id' => $applicantUser->applicant->id, |
125
|
|
|
])); |
126
|
|
|
$applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 2)->states('draft')->create([ |
127
|
|
|
'applicant_id' => $applicantUser->applicant->id, |
128
|
|
|
])); |
129
|
|
|
} |
130
|
|
|
} |
131
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.