| Conditions | 6 |
| Paths | 12 |
| Total Lines | 112 |
| Code Lines | 79 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 23 | public function show(Request $request, JobPoster $job) |
||
| 24 | { |
||
| 25 | $user = Auth::user(); |
||
| 26 | |||
| 27 | $applications = $job->submitted_applications; |
||
| 28 | $advisor = $user->hr_advisor; |
||
| 29 | $jobIsClaimed = ($advisor !== null) && |
||
| 30 | $advisor->claimed_job_ids->contains($job->id); |
||
| 31 | $hr_advisors = $job->hr_advisors; |
||
| 32 | |||
| 33 | $summaryLang = Lang::get('hr_advisor/job_summary'); |
||
| 34 | |||
| 35 | $job_review_data = [ |
||
| 36 | 'imgSrc' => '/images/job-process-summary-tool-edit.svg', |
||
| 37 | 'imgAlt' => "{$summaryLang['edit_poster_icon']} {$summaryLang['flat_icons']}", |
||
| 38 | 'text' => $summaryLang['edit_poster_button'], |
||
| 39 | 'url' => route(WhichPortal::prefixRoute('jobs.review'), $job), |
||
|
|
|||
| 40 | 'disabled' => false, |
||
| 41 | ]; |
||
| 42 | |||
| 43 | $job_preview_data = [ |
||
| 44 | 'imgSrc' => '/images/job-process-summary-tool-view.svg', |
||
| 45 | 'imgAlt' => "{$summaryLang['view_poster_icon']} {$summaryLang['flat_icons']}", |
||
| 46 | 'text' => $summaryLang['view_poster_button'], |
||
| 47 | 'url' => route(WhichPortal::prefixRoute('jobs.preview'), $job), |
||
| 48 | 'disabled' => false, |
||
| 49 | ]; |
||
| 50 | |||
| 51 | $screening_plan_data = [ |
||
| 52 | 'imgSrc' => '/images/job-process-summary-tool-screen.svg', |
||
| 53 | 'imgAlt' => "{$summaryLang['screening_plan_icon']} {$summaryLang['flat_icons']}", |
||
| 54 | 'text' => $summaryLang['screening_plan_button'], |
||
| 55 | 'url' => route(WhichPortal::prefixRoute('jobs.screening_plan'), $job), |
||
| 56 | 'disabled' => false |
||
| 57 | ]; |
||
| 58 | |||
| 59 | $view_applicants_data = [ |
||
| 60 | 'imgSrc' => '/images/job-process-summary-tool-applicants.svg', |
||
| 61 | 'imgAlt' => "{$summaryLang['view_applicants_icon']} {$summaryLang['flat_icons']}", |
||
| 62 | 'text' => $summaryLang['view_applicants_button'], |
||
| 63 | 'url' => route(WhichPortal::prefixRoute('jobs.applications'), $job), |
||
| 64 | 'disabled' => !$job->isClosed(), |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $status = $job->job_poster_status->name; |
||
| 68 | $status_description = $job->job_poster_status->description; |
||
| 69 | |||
| 70 | $portal = ''; |
||
| 71 | if (WhichPortal::isHrPortal()) { |
||
| 72 | $portal = 'hr'; |
||
| 73 | } elseif (WhichPortal::isManagerPortal()) { |
||
| 74 | $portal = 'manager'; |
||
| 75 | } |
||
| 76 | |||
| 77 | $transitionManager = new JobStatusTransitionManager(); |
||
| 78 | $transitionToButton = function (JobPosterStatusTransition $transition) use ($user, $job, $transitionManager) { |
||
| 79 | return [ |
||
| 80 | 'text' => $transition->name, |
||
| 81 | 'url' => route(WhichPortal::prefixRoute('jobs.setJobStatus'), [ |
||
| 82 | 'jobPoster' => $job, |
||
| 83 | 'status' => $transition->to->key |
||
| 84 | ]), |
||
| 85 | 'style' => array_key_exists('button_style', $transition->metadata) |
||
| 86 | ? $transition->metadata['button_style'] |
||
| 87 | : 'default', |
||
| 88 | 'disabled' => !$transitionManager->userCanTransition($user, $transition->from->key, $transition->to->key) |
||
| 89 | ]; |
||
| 90 | }; |
||
| 91 | $unclaimButton = [ |
||
| 92 | 'unclaim_job' => [ |
||
| 93 | 'text' => Lang::get('hr_advisor/job_summary.relinquish_button'), |
||
| 94 | 'url' => route('hr_advisor.jobs.unclaim', $job), |
||
| 95 | 'style' => 'stop', |
||
| 96 | 'disabled' => !$jobIsClaimed, |
||
| 97 | ] |
||
| 98 | ]; |
||
| 99 | |||
| 100 | $buttonGroups = []; |
||
| 101 | |||
| 102 | $transitionButtons = $transitionManager->legalTransitions($job->job_poster_status->key) |
||
| 103 | ->map($transitionToButton); |
||
| 104 | array_push($buttonGroups, $transitionButtons); |
||
| 105 | |||
| 106 | if (WhichPortal::isHrPortal()) { |
||
| 107 | array_push($buttonGroups, $unclaimButton); |
||
| 108 | } |
||
| 109 | |||
| 110 | $data = [ |
||
| 111 | // Localized strings. |
||
| 112 | 'summary' => $summaryLang, |
||
| 113 | 'job_status' => $status, |
||
| 114 | 'job_status_description' => $status_description, |
||
| 115 | 'is_claimed' => $jobIsClaimed, |
||
| 116 | // User data. |
||
| 117 | 'user' => $user, |
||
| 118 | // HR Advisor data. |
||
| 119 | 'hr_advisors' => $hr_advisors, |
||
| 120 | // Job Poster data. |
||
| 121 | 'job' => $job, |
||
| 122 | // Application data. |
||
| 123 | 'applications' => $applications, |
||
| 124 | 'side_button_groups' => $buttonGroups, |
||
| 125 | 'job_review_data' => $job_review_data, |
||
| 126 | 'job_preview_data' => $job_preview_data, |
||
| 127 | 'screening_plan_data' => $screening_plan_data, |
||
| 128 | 'view_applicants_data' => $view_applicants_data, |
||
| 129 | 'portal' => $portal, |
||
| 130 | ]; |
||
| 131 | |||
| 132 | return view( |
||
| 133 | 'common/job_summary/job_summary', |
||
| 134 | $data |
||
| 135 | ); |
||
| 153 |