| Conditions | 5 |
| Paths | 16 |
| Total Lines | 85 |
| Lines | 38 |
| Ratio | 44.71 % |
| 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 |
||
| 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 | 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 | ])->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 | ])->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 | 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 |