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