| Conditions | 26 |
| Paths | 5376 |
| Total Lines | 266 |
| Code Lines | 194 |
| 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 |
||
| 131 | public function show(Request $request, JobPoster $jobPoster) |
||
| 132 | { |
||
| 133 | $jobPoster->load([ |
||
| 134 | 'department', |
||
| 135 | 'criteria.skill.skill_type', |
||
| 136 | 'manager.team_culture', |
||
| 137 | 'manager.work_environment' |
||
| 138 | ]); |
||
| 139 | |||
| 140 | $user = Auth::user(); |
||
| 141 | |||
| 142 | // TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model. |
||
| 143 | $workplacePhotos = []; |
||
| 144 | foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
||
| 145 | $workplacePhotos[] = [ |
||
| 146 | 'description' => $photoCaption->description, |
||
| 147 | 'url' => '/images/user.png' |
||
| 148 | ]; |
||
| 149 | } |
||
| 150 | |||
| 151 | // TODO: replace route('manager.show',manager.id) in templates with link using slug. |
||
| 152 | $essential = $jobPoster->criteria->filter( |
||
| 153 | function ($value, $key) { |
||
| 154 | return $value->criteria_type->name == 'essential'; |
||
| 155 | } |
||
| 156 | )->sortBy('id'); |
||
| 157 | $asset = $jobPoster->criteria->filter( |
||
| 158 | function ($value, $key) { |
||
| 159 | return $value->criteria_type->name == 'asset'; |
||
| 160 | } |
||
| 161 | )->sortBy('id'); |
||
| 162 | $criteria = [ |
||
| 163 | 'essential' => $essential, |
||
| 164 | 'asset' => $asset, |
||
| 165 | ]; |
||
| 166 | |||
| 167 | $jobLang = Lang::get('applicant/job_post'); |
||
| 168 | |||
| 169 | $gocLang = Lang::get('common/goc'); |
||
| 170 | |||
| 171 | $skillsLang = Lang::get('common/skills'); |
||
| 172 | |||
| 173 | $skillsArray = []; |
||
| 174 | foreach ($essential as $criterion) { |
||
| 175 | $skillsArray[] = [ |
||
| 176 | 'skill' => $criterion['skill']['name'], |
||
| 177 | 'level' => $skillsLang['skill_levels'][$criterion |
||
| 178 | ->skill->skill_type->name][$criterion->skill_level->name], |
||
| 179 | ]; |
||
| 180 | } |
||
| 181 | foreach ($asset as $criterion) { |
||
| 182 | $skillsArray[] = [ |
||
| 183 | 'skill' => $criterion['skill']['name'], |
||
| 184 | 'level' => $skillsLang['skill_levels'][$criterion |
||
| 185 | ->skill->skill_type->name][$criterion->skill_level->name], |
||
| 186 | ]; |
||
| 187 | } |
||
| 188 | |||
| 189 | $skillsString = ''; |
||
| 190 | if (!empty($skillsArray)) { |
||
| 191 | $lastSkill = end($skillsArray); |
||
| 192 | foreach ($skillsArray as $skillItem) { |
||
| 193 | $skillsString .= $skillItem['skill'].' - '.$skillItem['level'].($skillItem == $lastSkill ? '.' : ', '); |
||
| 194 | } |
||
| 195 | } |
||
| 196 | |||
| 197 | $benefitsString = ''; |
||
| 198 | if (is_array($jobLang['structured_data']['benefits'])) { |
||
| 199 | foreach ($jobLang['structured_data']['benefits'] as $benefit) { |
||
| 200 | $benefitsString .= $benefit.' '; |
||
| 201 | } |
||
| 202 | } |
||
| 203 | |||
| 204 | $tasksString = ''; |
||
| 205 | if (is_array($jobPoster['job_poster_key_tasks'])) { |
||
| 206 | $lastTask = end($jobPoster['job_poster_key_tasks']); |
||
| 207 | foreach ($jobPoster['job_poster_key_tasks'] as $task) { |
||
| 208 | $tasksString .= $task['description'].' '.($skillItem == $lastSkill ? '' : ' | '); |
||
| 209 | } |
||
| 210 | } |
||
| 211 | |||
| 212 | $securityClearanceString = $jobLang['structured_data']['security_clearance_requirement_level'].': ' |
||
| 213 | .$jobPoster['security_clearance']['value'].'. ' |
||
| 214 | .$jobLang['structured_data']['security_clearance_requirement_description']; |
||
| 215 | |||
| 216 | $structuredData = [ |
||
| 217 | '@context' => 'https://schema.org', |
||
| 218 | '@type' => 'JobPosting', |
||
| 219 | '@id' => url()->current(), |
||
| 220 | 'url' => url('/'), |
||
| 221 | 'inLanguage' => app()->getLocale(), |
||
| 222 | 'applicantLocationRequirements' => [ |
||
| 223 | '@type' => 'Country', |
||
| 224 | 'sameAs' => 'https://www.wikidata.org/wiki/Q16', |
||
| 225 | 'name' => 'Canada' |
||
| 226 | ], |
||
| 227 | 'applicationContact' => [ |
||
| 228 | '@type' => 'ContactPoint', |
||
| 229 | 'email' => '[email protected]' |
||
| 230 | ], |
||
| 231 | 'baseSalary' => [ |
||
| 232 | '@type' => 'MonetaryAmount', |
||
| 233 | 'currency' => 'CAD', |
||
| 234 | 'minValue' => $jobPoster['salary_min'], |
||
| 235 | 'maxValue' => $jobPoster['salary_max'], |
||
| 236 | ], |
||
| 237 | 'datePosted' => $jobPoster['open_date_time'], |
||
| 238 | 'employerOverview' => $jobLang['structured_data']['employer_overview'], |
||
| 239 | 'employmentType' => $jobLang['structured_data']['employment_type'], |
||
| 240 | 'estimatedSalary' => [ |
||
| 241 | '@type' => 'MonetaryAmount', |
||
| 242 | 'currency' => 'CAD', |
||
| 243 | 'minValue' => $jobPoster['salary_min'], |
||
| 244 | 'maxValue' => $jobPoster['salary_max'] |
||
| 245 | ], |
||
| 246 | 'hiringOrganization' => [ |
||
| 247 | '@type' => 'GovernmentOrganization', |
||
| 248 | 'name' => $jobPoster['manager']['user']['department']['name'], |
||
| 249 | 'parentOrganization' => [ |
||
| 250 | '@type' => 'GovernmentOrganization', |
||
| 251 | 'name' => $jobLang['structured_data']['parent_organization'], |
||
| 252 | 'url' => $gocLang['logo_link'], |
||
| 253 | 'logo' => asset('/images/logo_canada_colour.png'), |
||
| 254 | ] |
||
| 255 | ], |
||
| 256 | 'industry' => $jobLang['structured_data']['industry'], |
||
| 257 | 'jobBenefits' => $benefitsString, |
||
| 258 | 'jobLocation' => [ |
||
| 259 | '@type' => 'Place', |
||
| 260 | 'address' => [ |
||
| 261 | '@type' => 'PostalAddress', |
||
| 262 | 'addressLocality' => $jobPoster['city'], |
||
| 263 | 'addressRegion' => $jobPoster['province']['value'], |
||
| 264 | 'addressCountry' => 'CA' |
||
| 265 | ] |
||
| 266 | ], |
||
| 267 | 'jobStartDate' => $jobPoster['start_date_time'], |
||
| 268 | 'qualifications' => $jobPoster['education'], |
||
| 269 | 'responsibilities' => $tasksString, |
||
| 270 | 'salaryCurrency' => 'CAD', |
||
| 271 | 'securityClearanceRequirement' => $securityClearanceString, |
||
| 272 | 'skills' => $skillsString, |
||
| 273 | 'specialCommitments' => $jobLang['structured_data']['special_commitments'], |
||
| 274 | 'title' => $jobPoster['title'], |
||
| 275 | 'totalJobOpenings' => '1', |
||
| 276 | 'validThrough' => $jobPoster['close_date_time'], |
||
| 277 | 'description' => $jobPoster['hire_impact'] ? nl2br($jobPoster['hire_impact']) : '', |
||
| 278 | ]; |
||
| 279 | |||
| 280 | if ($jobPoster['remote_work_allowed'] == true) { |
||
| 281 | $structuredData['jobLocationType'] = 'TELECOMMUTE'; |
||
| 282 | }; |
||
| 283 | |||
| 284 | $applyButton = []; |
||
| 285 | if (WhichPortal::isManagerPortal()) { |
||
| 286 | $applyButton = [ |
||
| 287 | 'href' => route('manager.jobs.edit', $jobPoster->id), |
||
| 288 | 'title' => $jobLang['apply']['edit_link_title'], |
||
| 289 | 'text' => $jobLang['apply']['edit_link_label'], |
||
| 290 | ]; |
||
| 291 | } elseif (WhichPortal::isHrPortal()) { |
||
| 292 | if ($jobPoster->hr_advisors->contains('user_id', $user->id)) { |
||
| 293 | $applyButton = [ |
||
| 294 | 'href' => route('hr_advisor.jobs.summary', $jobPoster->id), |
||
| 295 | 'title' => null, |
||
| 296 | 'text' => Lang::get('hr_advisor/job_summary.summary_title'), |
||
| 297 | ]; |
||
| 298 | } else { |
||
| 299 | $applyButton = [ |
||
| 300 | 'href' => route('hr_advisor.jobs.index'), |
||
| 301 | 'title' => null, |
||
| 302 | 'text' => Lang::get('hr_advisor/job_index.title'), |
||
| 303 | ]; |
||
| 304 | } |
||
| 305 | } elseif (Auth::check() && $jobPoster->isOpen()) { |
||
| 306 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
| 307 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
| 308 | // If applicants job application is not draft anymore then link to application preview page. |
||
| 309 | if ($application != null && $application->application_status->name != 'draft') { |
||
| 310 | $applyButton = [ |
||
| 311 | 'href' => route('applications.show', $application->id), |
||
| 312 | 'title' => $jobLang['apply']['view_link_title'], |
||
| 313 | 'text' => $jobLang['apply']['view_link_label'], |
||
| 314 | ]; |
||
| 315 | } else { |
||
| 316 | $applyButton = [ |
||
| 317 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
| 318 | 'title' => $jobLang['apply']['apply_link_title'], |
||
| 319 | 'text' => $jobLang['apply']['apply_link_label'], |
||
| 320 | ]; |
||
| 321 | } |
||
| 322 | } elseif (Auth::guest() && $jobPoster->isOpen()) { |
||
| 323 | $applyButton = [ |
||
| 324 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
| 325 | 'title' => $jobLang['apply']['login_link_title'], |
||
| 326 | 'text' => $jobLang['apply']['login_link_label'], |
||
| 327 | ]; |
||
| 328 | } else { |
||
| 329 | $applyButton = [ |
||
| 330 | 'href' => null, |
||
| 331 | 'title' => null, |
||
| 332 | 'text' => $jobLang['apply']['job_closed_label'], |
||
| 333 | ]; |
||
| 334 | } |
||
| 335 | |||
| 336 | $jpb_release_date = strtotime('2019-08-21 16:18:17'); |
||
| 337 | $job_created_at = strtotime($jobPoster->created_at); |
||
| 338 | |||
| 339 | $custom_breadcrumbs = [ |
||
| 340 | 'home' => route('home'), |
||
| 341 | 'jobs' => route(WhichPortal::prefixRoute('jobs.index')), |
||
| 342 | $jobPoster->title ?: 'job-title-missing' => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), |
||
| 343 | 'preview' => '', |
||
| 344 | ]; |
||
| 345 | |||
| 346 | // If the poster is part of the Strategic Talent Response dept, use the talent stream template. |
||
| 347 | // Else, If the job poster is created after the release of the JPB. |
||
| 348 | // Then, render with updated poster template. |
||
| 349 | // Else, render with old poster template. |
||
| 350 | if ($jobPoster->isInStrategicResponseDepartment()) { |
||
| 351 | return view( |
||
| 352 | 'applicant/strategic_response_job_post', |
||
| 353 | [ |
||
| 354 | 'job_post' => $jobLang, |
||
| 355 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 356 | 'skill_template' => $skillsLang, |
||
| 357 | 'job' => $jobPoster, |
||
| 358 | 'manager' => $jobPoster->manager, |
||
| 359 | 'criteria' => $criteria, |
||
| 360 | 'apply_button' => $applyButton, |
||
| 361 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
| 362 | ] |
||
| 363 | ); |
||
| 364 | } elseif ($job_created_at > $jpb_release_date) { |
||
| 365 | // Updated job poster (JPB). |
||
| 366 | return view( |
||
| 367 | 'applicant/jpb_job_post', |
||
| 368 | [ |
||
| 369 | 'job_post' => $jobLang, |
||
| 370 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 371 | 'skill_template' => $skillsLang, |
||
| 372 | 'job' => $jobPoster, |
||
| 373 | 'manager' => $jobPoster->manager, |
||
| 374 | 'criteria' => $criteria, |
||
| 375 | 'apply_button' => $applyButton, |
||
| 376 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
| 377 | 'structured_data' => $structuredData, |
||
| 378 | ] |
||
| 379 | ); |
||
| 380 | } else { |
||
| 381 | // Old job poster. |
||
| 382 | return view( |
||
| 383 | 'applicant/job_post', |
||
| 384 | [ |
||
| 385 | 'job_post' => $jobLang, |
||
| 386 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 387 | 'manager' => $jobPoster->manager, |
||
| 388 | 'manager_profile_photo_url' => '/images/user.png', // TODO get real photo. |
||
| 389 | 'team_culture' => $jobPoster->manager->team_culture, |
||
| 390 | 'work_environment' => $jobPoster->manager->work_environment, |
||
| 391 | 'workplace_photos' => $workplacePhotos, |
||
| 392 | 'job' => $jobPoster, |
||
| 393 | 'criteria' => $criteria, |
||
| 394 | 'apply_button' => $applyButton, |
||
| 395 | 'skill_template' => Lang::get('common/skills'), |
||
| 396 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
| 397 | ] |
||
| 594 |