Conditions | 5 |
Paths | 16 |
Total Lines | 83 |
Code Lines | 49 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
47 | public function run() : void |
||
48 | { |
||
49 | $adminUser = User::where('email', $this->adminEmail)->first(); |
||
50 | if ($adminUser === null) { |
||
51 | $adminUser = factory(User::class)->states('admin')->create(['email' => $this->adminEmail]); |
||
|
|||
52 | } |
||
53 | |||
54 | $managerUser = User::where('email', $this->managerEmail)->first(); |
||
55 | // Create the test manager if it does not exist yet |
||
56 | if ($managerUser === null) { |
||
57 | $managerUser = factory(User::class)->states('manager')->create(['email' => $this->managerEmail]); |
||
58 | $managerUser->manager()->save(factory(Manager::class)->create([ |
||
59 | 'user_id' => $managerUser->id |
||
60 | ])); |
||
61 | } |
||
62 | |||
63 | factory(JobPoster::class, 3)->states('published')->create([ |
||
64 | 'manager_id' => $managerUser->manager->id |
||
65 | ])->each(function ($job) : void { |
||
66 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
67 | 'job_poster_id' => $job->id |
||
68 | ]); |
||
69 | //Then create one application with a priority user |
||
70 | $job->job_applications()->save(factory(JobApplication::class)->create([ |
||
71 | 'job_poster_id' => $job->id, |
||
72 | 'applicant_id' => factory(Applicant::class)->create([ |
||
73 | 'user_id' => factory(User::class)->states('priority')->create()->id |
||
74 | ])->id |
||
75 | ])); |
||
76 | }); |
||
77 | factory(JobPoster::class, 3)->states('closed')->create([ |
||
78 | 'manager_id' => $managerUser->manager->id |
||
79 | ])->each(function ($job) : void { |
||
80 | $job->job_applications()->saveMany(factory(JobApplication::class, 5))->create([ |
||
81 | 'job_poster_id' => $job->id |
||
82 | ]); |
||
83 | //Then create one application with a priority user |
||
84 | $job->job_applications()->save(factory(JobApplication::class)->create([ |
||
85 | 'job_poster_id' => $job->id, |
||
86 | 'applicant_id' => factory(Applicant::class)->create([ |
||
87 | 'user_id' => factory(User::class)->state('priority')->create()->id |
||
88 | ])->id |
||
89 | ])); |
||
90 | }); |
||
91 | factory(JobPoster::class, 3)->states('draft')->create([ |
||
92 | 'manager_id' => $managerUser->manager->id |
||
93 | ]); |
||
94 | factory(JobPoster::class, 3)->states('review_requested')->create([ |
||
95 | 'manager_id' => $managerUser->manager->id |
||
96 | ]); |
||
97 | |||
98 | // Create a Job Poster with an Assessment Plan |
||
99 | $jobWithAssessment = factory(JobPoster::class)->states('draft')->create([ |
||
100 | 'manager_id' => $managerUser->manager->id, |
||
101 | ]); |
||
102 | foreach ($jobWithAssessment->criteria as $criterion) { |
||
103 | // Create an assessment for each criterion |
||
104 | factory(Assessment::class)->states('withRatingGuide')->create([ |
||
105 | 'criterion_id' => $criterion->id, |
||
106 | ]); |
||
107 | }; |
||
108 | |||
109 | $applicantUser = User::where('email', $this->applicantEmail)->first(); |
||
110 | if ($applicantUser === null) { |
||
111 | $applicantUser = factory(User::class)->states('applicant')->create([ |
||
112 | 'email' => $this->applicantEmail |
||
113 | ]); |
||
114 | $applicantUser->applicant()->save(factory(Applicant::class)->create([ |
||
115 | 'user_id' => $applicantUser->id |
||
116 | ])); |
||
117 | } |
||
118 | |||
119 | // Add to application profile |
||
120 | $applicantUser->applicant->references()->saveMany(factory(Reference::class, 3)->create([ |
||
121 | 'applicant_id' => $applicantUser->applicant->id |
||
122 | ])); |
||
123 | |||
124 | // Create several applications for test user. |
||
125 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 3)->create([ |
||
126 | 'applicant_id' => $applicantUser->applicant->id, |
||
127 | ])); |
||
128 | $applicantUser->applicant->job_applications()->saveMany(factory(JobApplication::class, 2)->states('draft')->create([ |
||
129 | 'applicant_id' => $applicantUser->applicant->id, |
||
130 | ])); |
||
133 |