Conditions | 14 |
Paths | 42 |
Total Lines | 150 |
Code Lines | 107 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 |
||
133 | public function show(Request $request, JobPoster $jobPoster) |
||
134 | { |
||
135 | $jobPoster->load([ |
||
136 | 'department', |
||
137 | 'criteria.skill.skill_type', |
||
138 | 'manager.team_culture', |
||
139 | 'manager.work_environment' |
||
140 | ]); |
||
141 | |||
142 | $user = Auth::user(); |
||
143 | |||
144 | // TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model. |
||
145 | $workplacePhotos = []; |
||
146 | foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
||
147 | $workplacePhotos[] = [ |
||
148 | 'description' => $photoCaption->description, |
||
149 | 'url' => '/images/user.png' |
||
150 | ]; |
||
151 | } |
||
152 | |||
153 | // TODO: replace route('manager.show',manager.id) in templates with link using slug. |
||
154 | $essential = $jobPoster->criteria->filter( |
||
155 | function ($value, $key) { |
||
156 | return $value->criteria_type->name == 'essential'; |
||
157 | } |
||
158 | )->sortBy('id'); |
||
159 | $asset = $jobPoster->criteria->filter( |
||
160 | function ($value, $key) { |
||
161 | return $value->criteria_type->name == 'asset'; |
||
162 | } |
||
163 | )->sortBy('id'); |
||
164 | $criteria = [ |
||
165 | 'essential' => $essential, |
||
166 | 'asset' => $asset, |
||
167 | ]; |
||
168 | |||
169 | $jobLang = Lang::get('applicant/job_post'); |
||
170 | |||
171 | $applyButton = []; |
||
172 | if (WhichPortal::isManagerPortal()) { |
||
173 | $applyButton = [ |
||
174 | 'href' => route('manager.jobs.edit', $jobPoster->id), |
||
175 | 'title' => $jobLang['apply']['edit_link_title'], |
||
176 | 'text' => $jobLang['apply']['edit_link_label'], |
||
177 | ]; |
||
178 | } elseif (WhichPortal::isHrPortal()) { |
||
179 | if ($jobPoster->hr_advisors->contains('user_id', $user->id)) { |
||
180 | $applyButton = [ |
||
181 | 'href' => route('hr_advisor.jobs.summary', $jobPoster->id), |
||
182 | 'title' => null, |
||
183 | 'text' => Lang::get('hr_advisor/job_summary.summary_title'), |
||
184 | ]; |
||
185 | } else { |
||
186 | $applyButton = [ |
||
187 | 'href' => route('hr_advisor.jobs.index'), |
||
188 | 'title' => null, |
||
189 | 'text' => Lang::get('hr_advisor/job_index.title'), |
||
190 | ]; |
||
191 | } |
||
192 | } elseif (Auth::check() && $jobPoster->isOpen()) { |
||
193 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
194 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
195 | // If applicants job application is not draft anymore then link to application preview page. |
||
196 | if ($application != null && $application->application_status->name != 'draft') { |
||
197 | $applyButton = [ |
||
198 | 'href' => route('applications.show', $application->id), |
||
199 | 'title' => $jobLang['apply']['view_link_title'], |
||
200 | 'text' => $jobLang['apply']['view_link_label'], |
||
201 | ]; |
||
202 | } else { |
||
203 | $applyButton = [ |
||
204 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
205 | 'title' => $jobLang['apply']['apply_link_title'], |
||
206 | 'text' => $jobLang['apply']['apply_link_label'], |
||
207 | ]; |
||
208 | } |
||
209 | } elseif (Auth::guest() && $jobPoster->isOpen()) { |
||
210 | $applyButton = [ |
||
211 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
212 | 'title' => $jobLang['apply']['login_link_title'], |
||
213 | 'text' => $jobLang['apply']['login_link_label'], |
||
214 | ]; |
||
215 | } else { |
||
216 | $applyButton = [ |
||
217 | 'href' => null, |
||
218 | 'title' => null, |
||
219 | 'text' => $jobLang['apply']['job_closed_label'], |
||
220 | ]; |
||
221 | } |
||
222 | |||
223 | $jpb_release_date = strtotime('2019-08-21 16:18:17'); |
||
224 | $job_created_at = strtotime($jobPoster->created_at); |
||
225 | |||
226 | $custom_breadcrumbs = [ |
||
227 | 'home' => route('home'), |
||
228 | 'jobs' => route(WhichPortal::prefixRoute('jobs.index')), |
||
229 | $jobPoster->title ?: 'job-title-missing' => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), |
||
230 | 'preview' => '', |
||
231 | ]; |
||
232 | |||
233 | // If the poster is part of the Strategic Talent Response dept, use the talent stream template. |
||
234 | // Else, If the job poster is created after the release of the JPB. |
||
235 | // Then, render with updated poster template. |
||
236 | // Else, render with old poster template. |
||
237 | if ($jobPoster->isInStrategicResponseDepartment()) { |
||
238 | return view( |
||
239 | 'applicant/strategic_response_job_post', |
||
240 | [ |
||
241 | 'job_post' => $jobLang, |
||
242 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
243 | 'skill_template' => Lang::get('common/skills'), |
||
244 | 'job' => $jobPoster, |
||
245 | 'manager' => $jobPoster->manager, |
||
246 | 'criteria' => $criteria, |
||
247 | 'apply_button' => $applyButton, |
||
248 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
249 | ] |
||
250 | ); |
||
251 | } elseif ($job_created_at > $jpb_release_date) { |
||
252 | // Updated job poster (JPB). |
||
253 | return view( |
||
254 | 'applicant/jpb_job_post', |
||
255 | [ |
||
256 | 'job_post' => $jobLang, |
||
257 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
258 | 'skill_template' => Lang::get('common/skills'), |
||
259 | 'job' => $jobPoster, |
||
260 | 'manager' => $jobPoster->manager, |
||
261 | 'criteria' => $criteria, |
||
262 | 'apply_button' => $applyButton, |
||
263 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
264 | ] |
||
265 | ); |
||
266 | } else { |
||
267 | // Old job poster. |
||
268 | return view( |
||
269 | 'applicant/job_post', |
||
270 | [ |
||
271 | 'job_post' => $jobLang, |
||
272 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
273 | 'manager' => $jobPoster->manager, |
||
274 | 'manager_profile_photo_url' => '/images/user.png', // TODO get real photo. |
||
275 | 'team_culture' => $jobPoster->manager->team_culture, |
||
276 | 'work_environment' => $jobPoster->manager->work_environment, |
||
277 | 'workplace_photos' => $workplacePhotos, |
||
278 | 'job' => $jobPoster, |
||
279 | 'criteria' => $criteria, |
||
280 | 'apply_button' => $applyButton, |
||
281 | 'skill_template' => Lang::get('common/skills'), |
||
282 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
283 | ] |
||
480 |