| Total Complexity | 54 |
| Total Lines | 657 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
Complex classes like ApplicationByJobController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use ApplicationByJobController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 28 | class ApplicationByJobController extends Controller |
||
| 29 | { |
||
| 30 | /** |
||
| 31 | * Display a listing of the resource. |
||
| 32 | * |
||
| 33 | * @return \Illuminate\Http\Response |
||
| 34 | */ |
||
| 35 | public function index() |
||
| 37 | // |
||
| 38 | } |
||
| 39 | |||
| 40 | /** |
||
| 41 | * Display the Application for the specified job |
||
| 42 | * |
||
| 43 | * @param \App\Models\JobPoster $jobPoster |
||
| 44 | * @return \Illuminate\Http\Response |
||
| 45 | */ |
||
| 46 | public function show(JobPoster $jobPoster) |
||
| 47 | { |
||
| 48 | // |
||
| 49 | } |
||
| 50 | |||
| 51 | protected function getApplicationFromJob(JobPoster $jobPoster) { |
||
| 62 | } |
||
| 63 | |||
| 64 | /** |
||
| 65 | * Show the form for editing Application basics for the specified job. |
||
| 66 | * |
||
| 67 | * @param \App\Models\JobPoster $jobPoster |
||
| 68 | * @return \Illuminate\Http\Response |
||
| 69 | */ |
||
| 70 | public function edit_basics(JobPoster $jobPoster) |
||
| 71 | { |
||
| 72 | |||
| 73 | $applicant = Auth::user()->applicant; |
||
| 74 | |||
| 75 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 76 | |||
| 77 | //This is an alternative way of using policies instead of via middleware |
||
| 78 | if (!Auth::user()->can('view', $application) || |
||
| 79 | !Auth::user()->can('update', $application)) { |
||
| 80 | abort(401); |
||
| 81 | } |
||
| 82 | |||
| 83 | return view('applicant/application_post_01', [ |
||
|
1 ignored issue
–
show
|
|||
| 84 | |||
| 85 | /* Application Template Data */ |
||
| 86 | "application_step" => 1, |
||
| 87 | "application_template" => Lang::get("applicant/application_template"), |
||
| 88 | "language_options" => PreferredLanguage::all(), |
||
| 89 | "citizenship_options" => CitizenshipDeclaration::all(), |
||
| 90 | "veteran_options" => VeteranStatus::all(), |
||
| 91 | "preferred_language_template" => Lang::get('common/preferred_language'), |
||
| 92 | "citizenship_declaration_template" => Lang::get('common/citizenship_declaration'), |
||
| 93 | "veteran_status_template" => Lang::get('common/veteran_status'), |
||
| 94 | |||
| 95 | /* Job Data */ |
||
| 96 | "job" => $jobPoster, |
||
| 97 | |||
| 98 | /* Applicant Data */ |
||
| 99 | "applicant" => $applicant, |
||
| 100 | "job_application" => $application, |
||
| 101 | |||
| 102 | /* Submission */ |
||
| 103 | "form_submit_action" => route('job.application.update.1', $jobPoster) |
||
| 104 | |||
| 105 | ]); |
||
| 106 | |||
| 107 | } |
||
| 108 | |||
| 109 | /** |
||
| 110 | * Show the form for editing Application Experience for the specified job. |
||
| 111 | * |
||
| 112 | * @param \App\Models\JobPoster $jobPoster |
||
| 113 | * @return \Illuminate\Http\Response |
||
| 114 | */ |
||
| 115 | public function edit_experience(JobPoster $jobPoster) |
||
| 116 | { |
||
| 117 | |||
| 118 | $applicant = Auth::user()->applicant; |
||
| 119 | |||
| 120 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 121 | |||
| 122 | return view('applicant/application_post_02', [ |
||
|
1 ignored issue
–
show
|
|||
| 123 | |||
| 124 | /* Application Template Data */ |
||
| 125 | "application_step" => 2, |
||
| 126 | "application_template" => Lang::get("applicant/application_template"), |
||
| 127 | |||
| 128 | /* Job Data */ |
||
| 129 | "job" => $jobPoster, |
||
| 130 | |||
| 131 | /* Applicant Data */ |
||
| 132 | "applicant" => $applicant, |
||
| 133 | "job_application" => $application, |
||
| 134 | |||
| 135 | /* Submission */ |
||
| 136 | "form_submit_action" => route('job.application.update.2', $jobPoster) |
||
| 137 | |||
| 138 | ]); |
||
| 139 | |||
| 140 | } |
||
| 141 | |||
| 142 | /** |
||
| 143 | * Show the form for editing Application Essential Skills for the specified job. |
||
| 144 | * |
||
| 145 | * @param \App\Models\JobPoster $jobPoster |
||
| 146 | * @return \Illuminate\Http\Response |
||
| 147 | */ |
||
| 148 | public function edit_essential_skills(JobPoster $jobPoster) |
||
| 149 | { |
||
| 150 | |||
| 151 | $applicant = Auth::user()->applicant; |
||
| 152 | |||
| 153 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 154 | |||
| 155 | $criteria = [ |
||
| 156 | 'essential' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 157 | return $value->criteria_type->name == 'essential'; |
||
| 158 | }), |
||
| 159 | 'asset' => $jobPoster->criteria->filter(function($value, $key) { |
||
| 160 | return $value->criteria_type->name == 'asset'; |
||
| 161 | }), |
||
| 162 | ]; |
||
| 163 | |||
| 164 | return view('applicant/application_post_03', [ |
||
|
1 ignored issue
–
show
|
|||
| 165 | |||
| 166 | /* Application Template Data */ |
||
| 167 | "application_step" => 3, |
||
| 168 | "application_template" => Lang::get("applicant/application_template"), |
||
| 169 | |||
| 170 | /* Job Data */ |
||
| 171 | "job" => $jobPoster, |
||
| 172 | |||
| 173 | /* Skills Data */ |
||
| 174 | "skills" => Skill::all(), |
||
| 175 | "skill_template" => Lang::get("common/skills"), |
||
| 176 | "criteria" => $criteria, |
||
| 177 | |||
| 178 | /* Applicant Data */ |
||
| 179 | "applicant" => $applicant, |
||
| 180 | "job_application" => $application, |
||
| 181 | |||
| 182 | /* Submission */ |
||
| 183 | "form_submit_action" => route('job.application.update.3', $jobPoster) |
||
| 184 | |||
| 185 | ]); |
||
| 186 | |||
| 187 | } |
||
| 188 | |||
| 189 | /** |
||
| 190 | * Show the form for editing Application Asset Skills for the specified job. |
||
| 191 | * |
||
| 192 | * @param \App\Models\JobPoster $jobPoster |
||
| 193 | * @return \Illuminate\Http\Response |
||
| 194 | */ |
||
| 195 | public function edit_asset_skills(JobPoster $jobPoster) |
||
| 231 | |||
| 232 | ]); |
||
| 233 | } |
||
| 234 | |||
| 235 | /** |
||
| 236 | * Show the Application Preview for the application for the specified job. |
||
| 237 | * |
||
| 238 | * @param \App\Models\JobPoster $jobPoster |
||
| 239 | * @return \Illuminate\Http\Response |
||
| 240 | */ |
||
| 241 | public function preview(JobPoster $jobPoster) { |
||
| 279 | |||
| 280 | ]); |
||
| 281 | } |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Show the application submission information. |
||
| 285 | * |
||
| 286 | * @param \App\Models\JobPoster $jobPoster |
||
| 287 | * @return \Illuminate\Http\Response |
||
| 288 | */ |
||
| 289 | public function complete(JobPoster $jobPoster) { |
||
| 290 | |||
| 291 | /* Include Applicant Data */ |
||
| 292 | |||
| 293 | $applicant = Auth::user()->applicant; |
||
| 294 | |||
| 295 | /* Include Application Data */ |
||
| 296 | |||
| 297 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 298 | |||
| 299 | /* Return the Completion View */ |
||
| 300 | |||
| 301 | return view('applicant/application_post_complete', [ |
||
|
1 ignored issue
–
show
|
|||
| 302 | |||
| 303 | /* Application Template Data */ |
||
| 304 | "application_template" => Lang::get("applicant/application_template"), |
||
| 305 | |||
| 306 | /* Job Data */ |
||
| 307 | "job" => $jobPoster, |
||
| 308 | |||
| 309 | /* Applicant Data */ |
||
| 310 | "applicant" => $applicant, |
||
| 311 | "job_application" => $application |
||
| 312 | |||
| 313 | ]); |
||
| 314 | |||
| 315 | } |
||
| 316 | |||
| 317 | /** |
||
| 318 | * Update the Application Basics in storage for the specified job. |
||
| 319 | * |
||
| 320 | * @param \Illuminate\Http\Request $request |
||
| 321 | * @param \App\Models\JobPoster $jobPoster |
||
| 322 | * @return \Illuminate\Http\Response |
||
| 323 | */ |
||
| 324 | public function update_basics(Request $request, JobPoster $jobPoster) |
||
| 325 | { |
||
| 326 | $input = $request->input(); |
||
| 327 | $applicant = Auth::user()->applicant; |
||
| 328 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 329 | |||
| 330 | $application->fill([ |
||
| 331 | 'citizenship_declaration_id' => $input['citizenship_declaration_id'], |
||
| 332 | 'veteran_status_id' => $input['veteran_status_id'], |
||
| 333 | 'preferred_language_id' => $input['preferred_language_id'], |
||
| 334 | ]); |
||
| 335 | $application->save(); |
||
| 336 | |||
| 337 | $questions = $jobPoster->job_poster_questions; |
||
| 338 | foreach($questions as $question) { |
||
| 339 | $answer = null; |
||
| 340 | if (isset($input['questions']) && |
||
| 341 | isset($input['questions'][$question->id])) { |
||
| 342 | $answer = $input['questions'][$question->id]; |
||
| 343 | } |
||
| 344 | $answerObj = $application->job_application_answers |
||
| 345 | ->firstWhere('job_poster_question_id', $question->id); |
||
| 346 | if ($answerObj == null) { |
||
| 347 | $answerObj = new JobApplicationAnswer(); |
||
| 348 | $answerObj->job_poster_question_id = $question->id; |
||
| 349 | $answerObj->job_application_id = $application->id; |
||
| 350 | } |
||
| 351 | $answerObj->answer = $answer; |
||
| 352 | $answerObj->save(); |
||
| 353 | } |
||
| 354 | |||
| 355 | return redirect( route('job.application.edit.2', $jobPoster)); |
||
|
1 ignored issue
–
show
|
|||
| 356 | } |
||
| 357 | |||
| 358 | /** |
||
| 359 | * Update the Application Basics in storage for the specified job. |
||
| 360 | * |
||
| 361 | * @param \Illuminate\Http\Request $request |
||
| 362 | * @param \App\Models\JobPoster $jobPoster |
||
| 363 | * @return \Illuminate\Http\Response |
||
| 364 | */ |
||
| 365 | public function update_experience(Request $request, JobPoster $jobPoster) |
||
| 366 | { |
||
| 367 | $input = $request->input(); |
||
| 368 | $applicant = Auth::user()->applicant; |
||
| 369 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 370 | |||
| 371 | //TODO: save stuff to application |
||
| 372 | |||
| 373 | //TODO: Note from Tristan: I did test this function, and it works as I expect, |
||
| 374 | //TODO: saving new/updated degrees, courses and work experiences |
||
| 375 | //TODO: to the profile. |
||
| 376 | $degrees = $input['degrees']; |
||
| 377 | |||
| 378 | //Save new degrees |
||
| 379 | if (isset($degrees['new'])) { |
||
| 380 | foreach($degrees['new'] as $degreeInput) { |
||
| 381 | $degree = new Degree(); |
||
| 382 | $degree->applicant_id = $applicant->id; |
||
| 383 | $degree->fill([ |
||
| 384 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
| 385 | 'area_of_study' => $degreeInput['area_of_study'], |
||
| 386 | 'institution' => $degreeInput['institution'], |
||
| 387 | 'thesis' => $degreeInput['thesis'], |
||
| 388 | 'start_date' => $degreeInput['start_date'], |
||
| 389 | 'end_date' => $degreeInput['end_date'] |
||
| 390 | ]); |
||
| 391 | $degree->save(); |
||
| 392 | } |
||
| 393 | } |
||
| 394 | |||
| 395 | //Update old degrees |
||
| 396 | if (isset($degrees['old'])) { |
||
| 397 | foreach($degrees['old'] as $id=>$degreeInput) { |
||
| 398 | //Ensure this degree belongs to this applicant |
||
| 399 | $degree = $applicant->degrees->firstWhere('id', $id); |
||
| 400 | if ($degree != null) { |
||
| 401 | $degree->fill([ |
||
| 402 | 'degree_type_id' => $degreeInput['degree_type_id'], |
||
| 403 | 'area_of_study' => $degreeInput['area_of_study'], |
||
| 404 | 'institution' => $degreeInput['institution'], |
||
| 405 | 'thesis' => $degreeInput['thesis'], |
||
| 406 | 'start_date' => $degreeInput['start_date'], |
||
| 407 | 'end_date' => $degreeInput['end_date'] |
||
| 408 | ]); |
||
| 409 | $degree->save(); |
||
| 410 | } else { |
||
| 411 | Debugbar::warning('Applicant '.$applicant->id.' attempted to update degree with invalid id '.$id); |
||
| 412 | } |
||
| 413 | } |
||
| 414 | } |
||
| 415 | |||
| 416 | $courses = $input['courses']; |
||
| 417 | |||
| 418 | //Save new courses |
||
| 419 | if (isset($courses['new'])) { |
||
| 420 | foreach($courses['new'] as $courseInput) { |
||
| 421 | $course = new Course(); |
||
| 422 | $course->applicant_id = $applicant->id; |
||
| 423 | $course->fill([ |
||
| 424 | 'name' => $courseInput['name'], |
||
| 425 | 'institution' => $courseInput['institution'], |
||
| 426 | 'course_status_id' => $courseInput['course_status_id'], |
||
| 427 | 'start_date' => $courseInput['start_date'], |
||
| 428 | 'end_date' => $courseInput['end_date'] |
||
| 429 | ]); |
||
| 430 | $course->save(); |
||
| 431 | } |
||
| 432 | } |
||
| 433 | |||
| 434 | //Update old courses |
||
| 435 | if (isset($courses['old'])) { |
||
| 436 | foreach($courses['old'] as $id=>$courseInput) { |
||
| 437 | //Ensure this course belongs to this applicant |
||
| 438 | $course = $applicant->courses->firstWhere('id', $id); |
||
| 439 | if ($course != null) { |
||
| 440 | $course->fill([ |
||
| 441 | 'name' => $courseInput['name'], |
||
| 442 | 'institution' => $courseInput['institution'], |
||
| 443 | 'course_status_id' => $courseInput['course_status_id'], |
||
| 444 | 'start_date' => $courseInput['start_date'], |
||
| 445 | 'end_date' => $courseInput['end_date'] |
||
| 446 | ]); |
||
| 447 | $course->save(); |
||
| 448 | } else { |
||
| 449 | Debugbar::warning('Applicant '.$applicant->id.' attempted to update course with invalid id '.$id); |
||
| 450 | } |
||
| 451 | } |
||
| 452 | } |
||
| 453 | |||
| 454 | $work_experiences = $input['work_experiences'] ; |
||
| 455 | |||
| 456 | //Save new work_experiences |
||
| 457 | if (isset($work_experiences['new'])) { |
||
| 458 | foreach($work_experiences['new'] as $workExperienceInput) { |
||
| 459 | $workExperience = new WorkExperience(); |
||
| 460 | $workExperience->applicant_id = $applicant->id; |
||
| 461 | $workExperience->fill([ |
||
| 462 | 'role' => $workExperienceInput['role'], |
||
| 463 | 'company' => $workExperienceInput['company'], |
||
| 464 | 'description' => $workExperienceInput['description'], |
||
| 465 | 'start_date' => $workExperienceInput['start_date'], |
||
| 466 | 'end_date' => $workExperienceInput['end_date'] |
||
| 467 | ]); |
||
| 468 | $workExperience->save(); |
||
| 469 | } |
||
| 470 | } |
||
| 471 | |||
| 472 | //Update old work_experiences |
||
| 473 | if (isset($work_experiences['old'])) { |
||
| 474 | foreach($work_experiences['old'] as $id=>$workExperienceInput) { |
||
| 475 | //Ensure this work_experience belongs to this applicant |
||
| 476 | $workExperience = $applicant->work_experiences->firstWhere('id', $id); |
||
| 477 | if ($workExperience != null) { |
||
| 478 | $workExperience->fill([ |
||
| 479 | 'role' => $workExperienceInput['role'], |
||
| 480 | 'company' => $workExperienceInput['company'], |
||
| 481 | 'description' => $workExperienceInput['description'], |
||
| 482 | 'start_date' => $workExperienceInput['start_date'], |
||
| 483 | 'end_date' => $workExperienceInput['end_date'] |
||
| 484 | ]); |
||
| 485 | $workExperience->save(); |
||
| 486 | } else { |
||
| 487 | Debugbar::warning('Applicant '.$applicant->id.' attempted to update work_experience with invalid id '.$id); |
||
| 488 | } |
||
| 489 | } |
||
| 490 | } |
||
| 491 | |||
| 492 | return redirect( route('job.application.edit.3', $jobPoster)); |
||
|
1 ignored issue
–
show
|
|||
| 493 | } |
||
| 494 | |||
| 495 | /** |
||
| 496 | * Update the Application Essential Skills in storage for the specified job. |
||
| 497 | * |
||
| 498 | * @param \Illuminate\Http\Request $request |
||
| 499 | * @param \App\Models\JobPoster $jobPoster |
||
| 500 | * @return \Illuminate\Http\Response |
||
| 501 | */ |
||
| 502 | public function update_essential_skills(Request $request, JobPoster $jobPoster) |
||
| 503 | { |
||
| 504 | $input = $request->input(); |
||
| 505 | $applicant = Auth::user()->applicant; |
||
| 506 | $application = $this->getApplicationFromJob($jobPoster); |
||
| 507 | |||
| 508 | //TODO: save stuff to application |
||
| 509 | |||
| 510 | //TODO: Note from Tristan: I haven't tested this. This was copied from the SkillsController. |
||
| 511 | //TODO: But for now, if we're just updating the Applicant's Profile through this page, |
||
| 512 | //TODO: then this same code, or something very close, should work. |
||
| 513 | |||
| 514 | $skillDeclarations = $input['skill_declarations']; |
||
| 515 | $claimedStatusId = SkillStatus::where('name', 'claimed')->firstOrFail()->id; |
||
| 516 | |||
| 517 | //Save new skill declarartions |
||
| 518 | if (isset($skillDeclarations['new'])) { |
||
| 519 | foreach($skillDeclarations['new'] as $skillType => $typeInput) { |
||
| 520 | foreach($typeInput as $criterion_id=>$skillDeclarationInput) { |
||
| 521 | $skillDeclaration = new SkillDeclaration(); |
||
| 522 | $skillDeclaration->applicant_id = $applicant->id; |
||
| 523 | $skillDeclaration->skill_id = Criteria::find($criterion_id)->skill->id; |
||
| 524 | $skillDeclaration->skill_status_id = $claimedStatusId; |
||
| 525 | $skillDeclaration->fill([ |
||
| 526 | 'description' => $skillDeclarationInput['description'], |
||
| 527 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 528 | ]); |
||
| 529 | $skillDeclaration->save(); |
||
| 530 | |||
| 531 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 532 | $skillDeclaration->references()->sync($referenceIds); |
||
| 533 | |||
| 534 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 535 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 536 | } |
||
| 537 | } |
||
| 538 | } |
||
| 539 | |||
| 540 | //Update old declarations |
||
| 541 | if (isset($skillDeclarations['old'])) { |
||
| 542 | foreach($skillDeclarations['old'] as $skillType => $typeInput) { |
||
| 543 | foreach($typeInput as $id=>$skillDeclarationInput) { |
||
| 544 | //Ensure this declaration belongs to this applicant |
||
| 545 | $skillDeclaration = $applicant->skill_declarations->firstWhere('id', $id); |
||
| 546 | if ($skillDeclaration != null) { |
||
| 547 | //skill_id and skill_status cannot be changed |
||
| 548 | $skillDeclaration->fill([ |
||
| 549 | 'description' => $skillDeclarationInput['description'], |
||
| 550 | 'skill_level_id' => isset($skillDeclarationInput['skill_level_id']) ? $skillDeclarationInput['skill_level_id'] : null, |
||
| 551 | ]); |
||
| 552 | $skillDeclaration->save(); |
||
| 553 | |||
| 554 | $referenceIds = $this->getRelativeIds($skillDeclarationInput, 'references'); |
||
| 555 | $skillDeclaration->references()->sync($referenceIds); |
||
| 556 | |||
| 557 | $sampleIds = $this->getRelativeIds($skillDeclarationInput, 'samples'); |
||
| 558 | $skillDeclaration->work_samples()->sync($sampleIds); |
||
| 559 | } else { |
||
| 560 | Debugbar::warning('Applicant '.$applicant->id.' attempted to update skill declaration with invalid id '.$id); |
||
| 561 | } |
||
| 562 | } |
||
| 563 | } |
||
| 564 | } |
||
| 565 | |||
| 566 | return redirect( route('job.application.edit.4', $jobPoster)); |
||
|
1 ignored issue
–
show
|
|||
| 567 | } |
||
| 568 | |||
| 569 | /** |
||
| 570 | * Update the Application Asset Skills in storage for the specified job. |
||
| 571 | * |
||
| 572 | * @param \Illuminate\Http\Request $request |
||
| 573 | * @param \App\Models\JobPoster $jobPoster |
||
| 574 | * @return \Illuminate\Http\Response |
||
| 575 | */ |
||
| 576 | public function update_asset_skills(Request $request, JobPoster $jobPoster) |
||
| 641 | } |
||
| 642 | |||
| 643 | /** |
||
| 644 | * Submit the Application for the specified job. |
||
| 645 | * |
||
| 646 | * @param \Illuminate\Http\Request $request |
||
| 647 | * @param \App\Models\JobPoster $jobPoster |
||
| 648 | * @return \Illuminate\Http\Response |
||
| 649 | */ |
||
| 650 | public function submit(Request $request, JobPoster $jobPoster) |
||
| 685 | } |
||
| 686 | } |
||
| 687 |