| Total Complexity | 48 |
| Total Lines | 601 |
| Duplicated Lines | 0 % |
| Coverage | 68.54% |
| Changes | 0 | ||
Complex classes like JobController 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 JobController, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 35 | class JobController extends Controller |
||
| 36 | { |
||
| 37 | /** |
||
| 38 | * Display a listing of JobPosters. |
||
| 39 | * |
||
| 40 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
||
| 41 | */ |
||
| 42 | public function index() |
||
| 65 | ]); |
||
| 66 | } |
||
| 67 | |||
| 68 | /** |
||
| 69 | * Display a listing of a manager's JobPosters. |
||
| 70 | * |
||
| 71 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
||
| 72 | */ |
||
| 73 | 1 | public function managerIndex() |
|
| 86 | ]); |
||
| 87 | } |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Submit the Job Poster for review. |
||
| 91 | * |
||
| 92 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 93 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 94 | * |
||
| 95 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
||
| 96 | */ |
||
| 97 | 1 | public function submitForReview(Request $request, JobPoster $jobPoster) |
|
| 118 | ]); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Delete a draft Job Poster. |
||
| 123 | * |
||
| 124 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 125 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 126 | * |
||
| 127 | * @return void |
||
| 128 | */ |
||
| 129 | public function destroy(Request $request, JobPoster $jobPoster) : void |
||
| 130 | { |
||
| 131 | $jobPoster->delete(); |
||
| 132 | } |
||
| 133 | |||
| 134 | /** |
||
| 135 | * Display the specified job poster. |
||
| 136 | * |
||
| 137 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 138 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 139 | * |
||
| 140 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
||
| 141 | */ |
||
| 142 | 4 | public function show(Request $request, JobPoster $jobPoster) |
|
| 219 | ] |
||
| 220 | ); |
||
| 221 | } |
||
| 222 | |||
| 223 | /** |
||
| 224 | * Create a blank job poster for the specified manager |
||
| 225 | * |
||
| 226 | * @param Manager $manager |
||
|
1 ignored issue
–
show
|
|||
| 227 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
||
| 228 | */ |
||
| 229 | 1 | public function createAsManager(Manager $manager) |
|
| 248 | } |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Display the form for creating a new Job Poster |
||
| 252 | * |
||
| 253 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 254 | * |
||
| 255 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
||
| 256 | */ |
||
| 257 | public function create(Request $request) |
||
| 258 | { |
||
| 259 | return $this->populateCreateView($request); |
||
| 260 | } |
||
| 261 | |||
| 262 | /** |
||
| 263 | * Display the form for editing an existing Job Poster |
||
| 264 | * |
||
| 265 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 266 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 267 | * |
||
| 268 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
||
| 269 | */ |
||
| 270 | 1 | public function edit(Request $request, JobPoster $jobPoster) |
|
| 271 | { |
||
| 272 | 1 | return $this->populateCreateView($request, $jobPoster); |
|
| 273 | } |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Get the manager from the request object and check if creating or editing |
||
| 277 | * |
||
| 278 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 279 | * @param \App\Models\JobPoster $jobPoster Optional Job Poster object. |
||
| 280 | * |
||
| 281 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory Job Create view |
||
| 282 | */ |
||
| 283 | 1 | public function populateCreateView(Request $request, JobPoster $jobPoster = null) |
|
| 380 | ] |
||
| 381 | ); |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Create a new resource in storage |
||
| 386 | * |
||
| 387 | * @param \Illuminate\Http\Request $request Incoming request object. |
||
| 388 | * @param \App\Models\JobPoster $jobPoster Optional Job Poster object. |
||
| 389 | * |
||
| 390 | * @return \Illuminate\Routing\Redirector|\Illuminate\Http\RedirectResponse A redirect to the Job Index |
||
| 391 | */ |
||
| 392 | 2 | public function store(Request $request, JobPoster $jobPoster = null) |
|
| 418 | } |
||
| 419 | |||
| 420 | /** |
||
| 421 | * Fill Job Poster model's properties and save |
||
| 422 | * |
||
| 423 | * @param mixed[] $input Field values. |
||
| 424 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 425 | * |
||
| 426 | * @return void |
||
| 427 | */ |
||
| 428 | 2 | protected function fillAndSaveJobPoster(array $input, JobPoster $jobPoster) : void |
|
| 429 | { |
||
| 430 | 2 | $jobPoster->fill( |
|
| 431 | [ |
||
| 432 | 2 | 'job_term_id' => JobTerm::where('name', 'month')->firstOrFail()->id, |
|
| 433 | 2 | 'term_qty' => $input['term_qty'], |
|
| 434 | 2 | 'open_date_time' => ptDayStartToUtcTime($input['open_date']), |
|
| 435 | 2 | 'close_date_time' => ptDayEndToUtcTime($input['close_date']), |
|
| 436 | 2 | 'start_date_time' => ptDayStartToUtcTime($input['start_date']), |
|
| 437 | 2 | 'department_id' => $input['department'], |
|
| 438 | 2 | 'province_id' => $input['province'], |
|
| 439 | 2 | 'salary_min' => $input['salary_min'], |
|
| 440 | 2 | 'salary_max' => $input['salary_max'], |
|
| 441 | 2 | 'noc' => $input['noc'], |
|
| 442 | 2 | 'classification' => $input['classification'], |
|
| 443 | 2 | 'security_clearance_id' => $input['security_clearance'], |
|
| 444 | 2 | 'language_requirement_id' => $input['language_requirement'], |
|
| 445 | 2 | 'remote_work_allowed' => (isset($input['remote_work_allowed']) ? $input['remote_work_allowed'] : false), |
|
| 446 | 'en' => [ |
||
| 447 | 2 | 'city' => $input['city'], |
|
| 448 | 2 | 'title' => $input['title']['en'], |
|
| 449 | 2 | 'impact' => $input['impact']['en'], |
|
| 450 | 2 | 'branch' => $input['branch']['en'], |
|
| 451 | 2 | 'division' => $input['division']['en'], |
|
| 452 | 2 | 'education' => $input['education']['en'], |
|
| 453 | ], |
||
| 454 | 'fr' => [ |
||
| 455 | 2 | 'city' => $input['city'], |
|
| 456 | 2 | 'title' => $input['title']['fr'], |
|
| 457 | 2 | 'impact' => $input['impact']['fr'], |
|
| 458 | 2 | 'branch' => $input['branch']['fr'], |
|
| 459 | 2 | 'division' => $input['division']['fr'], |
|
| 460 | 2 | 'education' => $input['education']['fr'], |
|
| 461 | ], |
||
| 462 | ] |
||
| 463 | ); |
||
| 464 | 2 | $jobPoster->save(); |
|
| 465 | 2 | } |
|
| 466 | |||
| 467 | /** |
||
| 468 | * Fill Job Poster's tasks and save |
||
| 469 | * |
||
| 470 | * @param mixed[] $input Field values. |
||
| 471 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 472 | * @param boolean $replace Remove existing relationships. |
||
| 473 | * |
||
| 474 | * @return void |
||
| 475 | */ |
||
| 476 | 2 | protected function fillAndSaveJobPosterTasks(array $input, JobPoster $jobPoster, bool $replace) : void |
|
| 500 | } |
||
| 501 | } |
||
| 502 | |||
| 503 | /** |
||
| 504 | * Fill Job Poster's questions and save |
||
| 505 | * |
||
| 506 | * @param mixed[] $input Field values. |
||
| 507 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 508 | * @param boolean $replace Remove existing relationships. |
||
| 509 | * |
||
| 510 | * @return void |
||
| 511 | */ |
||
| 512 | 2 | protected function fillAndSaveJobPosterQuestions(array $input, JobPoster $jobPoster, bool $replace) : void |
|
| 513 | { |
||
| 514 | 2 | if ($replace) { |
|
| 515 | 2 | $jobPoster->job_poster_questions()->delete(); |
|
| 516 | } |
||
| 517 | |||
| 518 | 2 | if (!array_key_exists('question', $input) || !is_array($input['question'])) { |
|
| 519 | 2 | return; |
|
| 520 | } |
||
| 521 | |||
| 522 | foreach ($input['question'] as $question) { |
||
| 523 | $jobQuestion = new JobPosterQuestion(); |
||
| 524 | $jobQuestion->job_poster_id = $jobPoster->id; |
||
| 525 | $jobQuestion->fill( |
||
| 526 | [ |
||
| 527 | 'en' => [ |
||
| 528 | 'question' => $question['question']['en'], |
||
| 529 | 'description' => $question['description']['en'] |
||
| 530 | ], |
||
| 531 | 'fr' => [ |
||
| 532 | 'question' => $question['question']['fr'], |
||
| 533 | 'description' => $question['description']['fr'] |
||
| 534 | ] |
||
| 535 | ] |
||
| 536 | ); |
||
| 537 | $jobQuestion->save(); |
||
| 538 | } |
||
| 539 | } |
||
| 540 | |||
| 541 | /** |
||
| 542 | * Fill Job Poster's criteria and save |
||
| 543 | * |
||
| 544 | * @param mixed[] $input Field values. |
||
| 545 | * @param \App\Models\JobPoster $jobPoster Job Poster object. |
||
| 546 | * @param boolean $replace Remove existing relationships. |
||
| 547 | * |
||
| 548 | * @return void |
||
| 549 | */ |
||
| 550 | 2 | protected function fillAndSaveJobPosterCriteria(array $input, JobPoster $jobPoster, bool $replace) : void |
|
| 551 | { |
||
| 552 | 2 | if ($replace) { |
|
| 553 | 2 | $jobPoster->criteria()->delete(); |
|
| 554 | } |
||
| 555 | |||
| 556 | 2 | if (!array_key_exists('criteria', $input) || !is_array($input['criteria'])) { |
|
| 557 | 2 | return; |
|
| 558 | } |
||
| 559 | |||
| 560 | $criteria = $input['criteria']; |
||
| 561 | |||
| 562 | $combinedCriteria = []; |
||
| 563 | if (isset($criteria['old'])) { |
||
| 564 | $combinedCriteria = array_replace_recursive($combinedCriteria, $criteria['old']); |
||
| 565 | } |
||
| 566 | if (isset($criteria['new'])) { |
||
| 567 | $combinedCriteria = array_replace_recursive($combinedCriteria, $criteria['new']); |
||
| 568 | } |
||
| 569 | |||
| 570 | if (! empty($combinedCriteria)) { |
||
| 571 | foreach ($combinedCriteria as $criteriaType => $criteriaTypeInput) { |
||
| 572 | foreach ($criteriaTypeInput as $skillType => $skillTypeInput) { |
||
| 573 | foreach ($skillTypeInput as $criteriaInput) { |
||
| 574 | $criteria = new Criteria(); |
||
| 575 | $criteria->job_poster_id = $jobPoster->id; |
||
| 576 | $criteria->fill( |
||
| 577 | [ |
||
| 578 | 'criteria_type_id' => CriteriaType::where('name', $criteriaType)->firstOrFail()->id, |
||
| 579 | 'skill_id' => $criteriaInput['skill_id'], |
||
| 580 | 'skill_level_id' => $criteriaInput['skill_level_id'], |
||
| 581 | 'en' => [ |
||
| 582 | 'description' => $criteriaInput['description']['en'], |
||
| 583 | ], |
||
| 584 | 'fr' => [ |
||
| 585 | 'description' => $criteriaInput['description']['fr'], |
||
| 586 | ], |
||
| 587 | ] |
||
| 588 | ); |
||
| 589 | $criteria->save(); |
||
| 590 | } |
||
| 591 | } |
||
| 592 | } |
||
| 593 | } |
||
| 594 | } |
||
| 595 | |||
| 596 | /** |
||
| 597 | * Get the localized default questions and add them to an array. |
||
| 598 | * |
||
| 599 | * @return mixed[]|void |
||
| 600 | */ |
||
| 601 | protected function populateDefaultQuestions() |
||
| 636 | } |
||
| 637 | } |
||
| 638 |