| Conditions | 7 |
| Paths | 64 |
| Total Lines | 130 |
| Code Lines | 80 |
| 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 |
||
| 65 | public function run(): void |
||
| 66 | { |
||
| 67 | $adminUser = User::where('email', $this->adminEmail)->first(); |
||
| 68 | if ($adminUser === null) { |
||
| 69 | $adminUser = factory(User::class)->state('admin')->create(['email' => $this->adminEmail]); |
||
| 70 | } |
||
| 71 | |||
| 72 | $hrUser = User::where('email', $this->hrAdvisorEmail)->first(); |
||
| 73 | if ($hrUser === null) { |
||
| 74 | $hrUser = factory(User::class)->state('hr_advisor')->create([ |
||
| 75 | 'email' => $this->hrAdvisorEmail, |
||
| 76 | ]); |
||
| 77 | $hrUser->hr_advisor()->save(factory(HrAdvisor::class)->create([ |
||
| 78 | 'user_id' => $hrUser->id, |
||
| 79 | ])); |
||
| 80 | } |
||
| 81 | |||
| 82 | $managerUser = User::where('email', $this->managerEmail)->first(); |
||
| 83 | // Create the test manager if it does not exist yet. |
||
| 84 | if ($managerUser === null) { |
||
| 85 | $managerUser = factory(User::class)->state('upgradedManager')->create(['email' => $this->managerEmail]); |
||
| 86 | $managerUser->manager()->save(factory(Manager::class)->create([ |
||
| 87 | 'user_id' => $managerUser->id |
||
| 88 | ])); |
||
| 89 | } |
||
| 90 | |||
| 91 | factory(JobPoster::class, 3)->state('live')->create([ |
||
| 92 | 'manager_id' => $managerUser->manager->id |
||
| 93 | ])->each(function ($job): void { |
||
| 94 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
| 95 | 'job_poster_id' => $job->id |
||
| 96 | ]); |
||
| 97 | // Then create one application with a priority user. |
||
| 98 | $job->job_applications()->save(factory(JobApplication::class)->states(['version2', 'submitted'])->create([ |
||
| 99 | 'job_poster_id' => $job->id, |
||
| 100 | 'applicant_id' => factory(Applicant::class)->create([ |
||
| 101 | 'user_id' => factory(User::class)->state('priority')->create()->id |
||
| 102 | ])->id, |
||
| 103 | ])); |
||
| 104 | }); |
||
| 105 | factory(JobPoster::class, 3)->state('closed')->create([ |
||
| 106 | 'manager_id' => $managerUser->manager->id |
||
| 107 | ])->each(function ($job): void { |
||
| 108 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
| 109 | 'job_poster_id' => $job->id |
||
| 110 | ]); |
||
| 111 | // Then create one application with a priority user. |
||
| 112 | $job->job_applications()->save(factory(JobApplication::class)->states(['version2', 'submitted'])->create([ |
||
| 113 | 'job_poster_id' => $job->id, |
||
| 114 | 'applicant_id' => factory(Applicant::class)->create([ |
||
| 115 | 'user_id' => factory(User::class)->state('priority')->create()->id |
||
| 116 | ])->id, |
||
| 117 | ])); |
||
| 118 | }); |
||
| 119 | factory(JobPoster::class, 3)->state('draft')->create([ |
||
| 120 | 'manager_id' => $managerUser->manager->id |
||
| 121 | ]); |
||
| 122 | factory(JobPoster::class, 3)->state('review_requested')->create([ |
||
| 123 | 'manager_id' => $managerUser->manager->id |
||
| 124 | ]); |
||
| 125 | |||
| 126 | // Create a Job Poster with an Assessment Plan. |
||
| 127 | $jobWithAssessment = factory(JobPoster::class)->state('draft')->create([ |
||
| 128 | 'manager_id' => $managerUser->manager->id, |
||
| 129 | ]); |
||
| 130 | foreach ($jobWithAssessment->criteria as $criterion) { |
||
| 131 | // Create an assessment for each criterion. |
||
| 132 | factory(Assessment::class)->state('withRatingGuide')->create([ |
||
| 133 | 'criterion_id' => $criterion->id, |
||
| 134 | ]); |
||
| 135 | }; |
||
| 136 | |||
| 137 | $applicantUser = User::where('email', $this->applicantEmail)->first(); |
||
| 138 | if ($applicantUser === null) { |
||
| 139 | $applicantUser = factory(User::class)->state('applicant')->create([ |
||
| 140 | 'email' => $this->applicantEmail |
||
| 141 | ]); |
||
| 142 | $applicantUser->applicant()->save(factory(Applicant::class)->create([ |
||
| 143 | 'user_id' => $applicantUser->id |
||
| 144 | ])); |
||
| 145 | } |
||
| 146 | |||
| 147 | $newApplicantUser = User::where('email', $this->newApplicantEmail)->first(); |
||
| 148 | if ($newApplicantUser === null) { |
||
| 149 | $newApplicantUser = factory(User::class)->state('applicant')->create([ |
||
| 150 | 'email' => $this->newApplicantEmail |
||
| 151 | ]); |
||
| 152 | $newApplicantUser->applicant()->save(factory(Applicant::class)->create([ |
||
| 153 | 'user_id' => $newApplicantUser->id |
||
| 154 | ])); |
||
| 155 | } |
||
| 156 | |||
| 157 | // Add to application profile. |
||
| 158 | $applicantUser->applicant->references()->saveMany(factory(Reference::class, 3)->create([ |
||
| 159 | 'referenceable_id' => $applicantUser->applicant->id |
||
| 160 | ])); |
||
| 161 | $applicantUser->applicant->degrees()->saveMany(factory(Degree::class, 2)->create([ |
||
| 162 | 'degreeable_id' => $applicantUser->applicant->id |
||
| 163 | ])); |
||
| 164 | $applicantUser->applicant->courses()->saveMany(factory(Course::class, 3)->create([ |
||
| 165 | 'courseable_id' => $applicantUser->applicant->id |
||
| 166 | ])); |
||
| 167 | $applicantUser->applicant->work_experiences()->saveMany(factory(WorkExperience::class, 3)->create([ |
||
| 168 | 'experienceable_id' => $applicantUser->applicant->id |
||
| 169 | ])); |
||
| 170 | |||
| 171 | // Create several applications for test user. |
||
| 172 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 3)->create([ |
||
| 173 | 'applicant_id' => $applicantUser->applicant->id, |
||
| 174 | ])); |
||
| 175 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 2)->state('draft')->create([ |
||
| 176 | 'applicant_id' => $applicantUser->applicant->id, |
||
| 177 | ])); |
||
| 178 | |||
| 179 | // Ensure there are several jobs the hr advisor can claim. |
||
| 180 | $hrDepartment = $hrUser->department_id; |
||
| 181 | factory(JobPoster::class)->states(['byUpgradedManager', 'draft']) |
||
| 182 | ->create(['department_id' => $hrDepartment]); |
||
| 183 | factory(JobPoster::class)->states(['byUpgradedManager', 'review_requested']) |
||
| 184 | ->create(['department_id' => $hrDepartment]); |
||
| 185 | $hrOpenJob = factory(JobPoster::class)->states(['byUpgradedManager', 'live']) |
||
| 186 | ->create(['department_id' => $hrDepartment]); |
||
| 187 | $hrClosedJob = factory(JobPoster::class)->states(['byUpgradedManager', 'closed']) |
||
| 188 | ->create(['department_id' => $hrDepartment]); |
||
| 189 | |||
| 190 | $hrOpenJob->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
| 191 | 'job_poster_id' => $hrOpenJob->id |
||
| 192 | ]); |
||
| 193 | $hrClosedJob->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
| 194 | 'job_poster_id' => $hrClosedJob->id |
||
| 195 | ]); |
||
| 198 |