Conditions | 8 |
Paths | 128 |
Total Lines | 191 |
Code Lines | 111 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
69 | public function run(): void |
||
70 | { |
||
71 | /* |
||
72 | Get random department_id. |
||
73 | Use departmentId to ensure any jobs that are attached to a given user belong to that user's department. |
||
74 | */ |
||
75 | $departmentId = Department::inRandomOrder()->first()->id; |
||
76 | |||
77 | $adminUser = User::where('email', $this->adminEmail)->first(); |
||
78 | if ($adminUser === null) { |
||
79 | $adminUser = factory(User::class)->state('admin')->create([ |
||
80 | 'email' => $this->adminEmail, |
||
81 | 'department_id' => $departmentId, |
||
82 | ]); |
||
83 | } |
||
84 | |||
85 | $hrUser = User::where('email', $this->hrAdvisorEmail)->first(); |
||
86 | if ($hrUser === null) { |
||
87 | $hrUser = factory(User::class)->state('hr_advisor')->create([ |
||
88 | 'email' => $this->hrAdvisorEmail, |
||
89 | 'department_id' => $departmentId, |
||
90 | ]); |
||
91 | $hrUser->hr_advisor()->save(factory(HrAdvisor::class)->create([ |
||
92 | 'user_id' => $hrUser->id, |
||
93 | ])); |
||
94 | } |
||
95 | |||
96 | $managerUser = User::where('email', $this->managerEmail)->first(); |
||
97 | // Create the test manager if it does not exist yet. |
||
98 | if ($managerUser === null) { |
||
99 | $managerUser = factory(User::class)->state('upgradedManager')->create([ |
||
100 | 'email' => $this->managerEmail, |
||
101 | 'department_id' => $departmentId, |
||
102 | ]); |
||
103 | $managerUser->manager()->save(factory(Manager::class)->create([ |
||
104 | 'user_id' => $managerUser->id, |
||
105 | ])); |
||
106 | } |
||
107 | |||
108 | factory(JobPoster::class, 3)->state('live')->create([ |
||
109 | 'manager_id' => $managerUser->manager->id, |
||
110 | 'department_id' => $departmentId, |
||
111 | ])->each(function ($job): void { |
||
112 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
113 | 'job_poster_id' => $job->id |
||
114 | ]); |
||
115 | // Then create one application with a priority user. |
||
116 | $job->job_applications()->save(factory(JobApplication::class)->states(['version2', 'submitted'])->create([ |
||
117 | 'job_poster_id' => $job->id, |
||
118 | 'applicant_id' => factory(Applicant::class)->create([ |
||
119 | 'user_id' => factory(User::class)->state('priority')->create()->id |
||
120 | ])->id, |
||
121 | ])); |
||
122 | }); |
||
123 | factory(JobPoster::class, 3)->state('closed')->create([ |
||
124 | 'manager_id' => $managerUser->manager->id, |
||
125 | 'department_id' => $departmentId, |
||
126 | ])->each(function ($job): void { |
||
127 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
128 | 'job_poster_id' => $job->id |
||
129 | ]); |
||
130 | // Then create one application with a priority user. |
||
131 | $job->job_applications()->save(factory(JobApplication::class)->states(['version2', 'submitted'])->create([ |
||
132 | 'job_poster_id' => $job->id, |
||
133 | 'applicant_id' => factory(Applicant::class)->create([ |
||
134 | 'user_id' => factory(User::class)->state('priority')->create()->id |
||
135 | ])->id, |
||
136 | ])); |
||
137 | }); |
||
138 | factory(JobPoster::class, 3)->state('draft')->create([ |
||
139 | 'manager_id' => $managerUser->manager->id, |
||
140 | 'department_id' => $departmentId, |
||
141 | ]); |
||
142 | factory(JobPoster::class, 3)->state('review_requested')->create([ |
||
143 | 'manager_id' => $managerUser->manager->id, |
||
144 | 'department_id' => $departmentId, |
||
145 | ]); |
||
146 | |||
147 | // Create a Job Poster with an Assessment Plan. |
||
148 | $jobWithAssessment = factory(JobPoster::class)->state('draft')->create([ |
||
149 | 'manager_id' => $managerUser->manager->id, |
||
150 | ]); |
||
151 | foreach ($jobWithAssessment->criteria as $criterion) { |
||
152 | // Create an assessment for each criterion. |
||
153 | factory(Assessment::class)->state('withRatingGuide')->create([ |
||
154 | 'criterion_id' => $criterion->id, |
||
155 | ]); |
||
156 | }; |
||
157 | |||
158 | $applicantUser = User::where('email', $this->applicantEmail)->first(); |
||
159 | if ($applicantUser === null) { |
||
160 | $applicantUser = factory(User::class)->state('applicant')->create([ |
||
161 | 'email' => $this->applicantEmail |
||
162 | ]); |
||
163 | $applicantUser->applicant()->save(factory(Applicant::class)->create([ |
||
164 | 'user_id' => $applicantUser->id |
||
165 | ])); |
||
166 | } |
||
167 | |||
168 | $newApplicantUser = User::where('email', $this->newApplicantEmail)->first(); |
||
169 | if ($newApplicantUser === null) { |
||
170 | $newApplicantUser = factory(User::class)->state('applicant')->create([ |
||
171 | 'email' => $this->newApplicantEmail |
||
172 | ]); |
||
173 | $newApplicantUser->applicant()->save(factory(Applicant::class)->create([ |
||
174 | 'user_id' => $newApplicantUser->id |
||
175 | ])); |
||
176 | } |
||
177 | |||
178 | // Add to application profile. |
||
179 | $applicantUser->applicant->references()->saveMany(factory(Reference::class, 3)->create([ |
||
180 | 'referenceable_id' => $applicantUser->applicant->id |
||
181 | ])); |
||
182 | $applicantUser->applicant->degrees()->saveMany(factory(Degree::class, 2)->create([ |
||
183 | 'degreeable_id' => $applicantUser->applicant->id |
||
184 | ])); |
||
185 | $applicantUser->applicant->courses()->saveMany(factory(Course::class, 3)->create([ |
||
186 | 'courseable_id' => $applicantUser->applicant->id |
||
187 | ])); |
||
188 | $applicantUser->applicant->work_experiences()->saveMany(factory(WorkExperience::class, 3)->create([ |
||
189 | 'experienceable_id' => $applicantUser->applicant->id |
||
190 | ])); |
||
191 | |||
192 | // Create several applications for test user. |
||
193 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 1) |
||
194 | ->state('submitted')->create([ |
||
195 | 'applicant_id' => $applicantUser->applicant->id, |
||
196 | ])); |
||
197 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 1) |
||
198 | ->states(['version2', 'submitted'])->create([ |
||
199 | 'applicant_id' => $applicantUser->applicant->id, |
||
200 | ])); |
||
201 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 1) |
||
202 | ->state('draft')->create([ |
||
203 | 'applicant_id' => $applicantUser->applicant->id, |
||
204 | ])); |
||
205 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 1) |
||
206 | ->states(['draft', 'version2'])->create([ |
||
207 | 'applicant_id' => $applicantUser->applicant->id, |
||
208 | ])); |
||
209 | |||
210 | // Get five skill ids at random. |
||
211 | $applicantSkills = Skill::inRandomOrder()->limit(5)->get()->pluck('id')->toArray(); |
||
212 | |||
213 | // Add skills to applicant user. |
||
214 | $applicantUser->applicant->skills()->attach($applicantSkills); |
||
215 | |||
216 | // Ensure there are several jobs the hr advisor can claim. |
||
217 | $hrDepartment = $hrUser->department_id; |
||
218 | factory(JobPoster::class)->states(['byUpgradedManager', 'draft']) |
||
219 | ->create(['department_id' => $hrDepartment]); |
||
220 | factory(JobPoster::class)->states(['byUpgradedManager', 'review_requested']) |
||
221 | ->create(['department_id' => $hrDepartment]); |
||
222 | $hrOpenJob = factory(JobPoster::class)->states(['byUpgradedManager', 'live']) |
||
223 | ->create(['department_id' => $hrDepartment]); |
||
224 | $hrClosedJob = factory(JobPoster::class)->states(['byUpgradedManager', 'closed']) |
||
225 | ->create(['department_id' => $hrDepartment]); |
||
226 | |||
227 | $hrOpenJob->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
228 | 'job_poster_id' => $hrOpenJob->id |
||
229 | ]); |
||
230 | $hrClosedJob->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
231 | 'job_poster_id' => $hrClosedJob->id |
||
232 | ]); |
||
233 | |||
234 | // Create first parent skill category. |
||
235 | $skillCategoryParentFirst = factory(SkillCategory::class, 1)->create(['depth' => 1]); |
||
236 | |||
237 | // Create second parent skill category. |
||
238 | $skillCategoryParentSecond = factory(SkillCategory::class, 1)->create(['depth' => 1]); |
||
239 | |||
240 | // Create child categories for the first parent category. |
||
241 | factory(SkillCategory::class, 4)->create([ |
||
242 | 'parent_id' => $skillCategoryParentFirst->first()->id, |
||
243 | 'depth' => 2 |
||
244 | ]); |
||
245 | |||
246 | // Create child categories for the second parent category. |
||
247 | factory(SkillCategory::class, 4)->create([ |
||
248 | 'parent_id' => $skillCategoryParentSecond->first()->id, |
||
249 | 'depth' => 2 |
||
250 | ]); |
||
251 | |||
252 | // Create relationship between skill and skill category. |
||
253 | $skills = Skill::all(); |
||
254 | foreach ($skills as $skill) { |
||
255 | /* |
||
256 | Include skill categories created. |
||
257 | Exclude skill categories created that do not have children. |
||
258 | */ |
||
259 | $skill->skill_categories()->attach([rand(3, 10)]); |
||
260 | } |
||
263 |