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