Conditions | 10 |
Paths | 24 |
Total Lines | 113 |
Code Lines | 77 |
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 |
||
124 | public function show(Request $request, JobPoster $jobPoster) |
||
125 | { |
||
126 | $jobPoster->load([ |
||
127 | 'department', |
||
128 | 'criteria.skill.skill_type', |
||
129 | 'manager.team_culture', |
||
130 | 'manager.work_environment' |
||
131 | ]); |
||
132 | |||
133 | $user = Auth::user(); |
||
134 | |||
135 | // TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model. |
||
136 | $workplacePhotos = []; |
||
137 | foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
||
138 | $workplacePhotos[] = [ |
||
139 | 'description' => $photoCaption->description, |
||
140 | 'url' => '/images/user.png' |
||
141 | ]; |
||
142 | } |
||
143 | |||
144 | // TODO: replace route('manager.show',manager.id) in templates with link using slug. |
||
145 | $criteria = [ |
||
146 | 'essential' => $jobPoster->criteria->filter( |
||
147 | function ($value, $key) { |
||
148 | return $value->criteria_type->name == 'essential'; |
||
149 | } |
||
150 | ), |
||
151 | 'asset' => $jobPoster->criteria->filter( |
||
152 | function ($value, $key) { |
||
153 | return $value->criteria_type->name == 'asset'; |
||
154 | } |
||
155 | ), |
||
156 | ]; |
||
157 | |||
158 | $jobLang = Lang::get('applicant/job_post'); |
||
159 | |||
160 | $applyButton = []; |
||
161 | if (WhichPortal::isManagerPortal()) { |
||
162 | $applyButton = [ |
||
163 | 'href' => route('manager.jobs.edit', $jobPoster->id), |
||
164 | 'title' => $jobLang['apply']['edit_link_title'], |
||
165 | 'text' => $jobLang['apply']['edit_link_label'], |
||
166 | ]; |
||
167 | } elseif (WhichPortal::isHrPortal()) { |
||
168 | if ($jobPoster->hr_advisors->contains('user_id', $user->id)) { |
||
169 | $applyButton = [ |
||
170 | 'href' => route('hr_advisor.jobs.summary', $jobPoster->id), |
||
171 | 'title' => null, |
||
172 | 'text' => Lang::get('hr_advisor/job_summary.summary_title'), |
||
173 | ]; |
||
174 | } else { |
||
175 | $applyButton = [ |
||
176 | 'href' => route('hr_advisor.jobs.index'), |
||
177 | 'title' => null, |
||
178 | 'text' => Lang::get('hr_advisor/job_index.title'), |
||
179 | ]; |
||
180 | } |
||
181 | } elseif (Auth::check() && $jobPoster->isOpen()) { |
||
182 | $applyButton = [ |
||
183 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
184 | 'title' => $jobLang['apply']['apply_link_title'], |
||
185 | 'text' => $jobLang['apply']['apply_link_label'], |
||
186 | ]; |
||
187 | } elseif (Auth::guest() && $jobPoster->isOpen()) { |
||
188 | $applyButton = [ |
||
189 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
190 | 'title' => $jobLang['apply']['login_link_title'], |
||
191 | 'text' => $jobLang['apply']['login_link_label'], |
||
192 | ]; |
||
193 | } else { |
||
194 | $applyButton = [ |
||
195 | 'href' => null, |
||
196 | 'title' => null, |
||
197 | 'text' => $jobLang['apply']['job_closed_label'], |
||
198 | ]; |
||
199 | } |
||
200 | |||
201 | $jpb_release_date = strtotime('2019-08-21 16:18:17'); |
||
202 | $job_created_at = strtotime($jobPoster->created_at); |
||
203 | |||
204 | // If the job poster is created after the release of the JPB. |
||
205 | // Then, render with updated poster template. |
||
206 | // Else, render with old poster template. |
||
207 | if ($job_created_at > $jpb_release_date) { |
||
208 | // Updated job poster (JPB). |
||
209 | return view( |
||
210 | 'applicant/jpb_job_post', |
||
211 | [ |
||
212 | 'job_post' => $jobLang, |
||
213 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
214 | 'skill_template' => Lang::get('common/skills'), |
||
215 | 'job' => $jobPoster, |
||
216 | 'manager' => $jobPoster->manager, |
||
217 | 'criteria' => $criteria, |
||
218 | 'apply_button' => $applyButton, |
||
219 | ] |
||
220 | ); |
||
221 | } else { |
||
222 | // Old job poster. |
||
223 | return view( |
||
224 | 'applicant/job_post', |
||
225 | [ |
||
226 | 'job_post' => $jobLang, |
||
227 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
228 | 'manager' => $jobPoster->manager, |
||
229 | 'manager_profile_photo_url' => '/images/user.png', // TODO get real photo. |
||
230 | 'team_culture' => $jobPoster->manager->team_culture, |
||
231 | 'work_environment' => $jobPoster->manager->work_environment, |
||
232 | 'workplace_photos' => $workplacePhotos, |
||
233 | 'job' => $jobPoster, |
||
234 | 'criteria' => $criteria, |
||
235 | 'apply_button' => $applyButton, |
||
236 | 'skill_template' => Lang::get('common/skills'), |
||
237 | ] |
||
398 |