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