| Conditions | 6 |
| Paths | 12 |
| Total Lines | 117 |
| Code Lines | 84 |
| 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 $jobPoster) |
||
| 24 | { |
||
| 25 | $user = Auth::user(); |
||
| 26 | |||
| 27 | $applications = $jobPoster->submitted_applications; |
||
| 28 | $advisor = $user->hr_advisor; |
||
| 29 | $jobIsClaimed = ($advisor !== null) && |
||
| 30 | $advisor->claimed_job_ids->contains($jobPoster->id); |
||
| 31 | $hr_advisors = $jobPoster->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'), $jobPoster), |
||
|
|
|||
| 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'), $jobPoster), |
||
| 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'), $jobPoster), |
||
| 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'), $jobPoster), |
||
| 64 | 'disabled' => !$user->can('reviewApplicationsFor', $jobPoster), |
||
| 65 | ]; |
||
| 66 | |||
| 67 | $status = $jobPoster->job_poster_status->name; |
||
| 68 | $status_description = $jobPoster->job_poster_status->description; |
||
| 69 | |||
| 70 | $portal = ''; |
||
| 71 | if (WhichPortal::isHrPortal()) { |
||
| 72 | $portal = 'hr'; |
||
| 73 | $menuLang = Lang::get('hr_advisor/menu'); |
||
| 74 | } elseif (WhichPortal::isManagerPortal()) { |
||
| 75 | $portal = 'manager'; |
||
| 76 | $menuLang = Lang::get('manager/menu'); |
||
| 77 | } |
||
| 78 | |||
| 79 | $transitionManager = new JobStatusTransitionManager(); |
||
| 80 | $transitionToButton = function (JobPosterStatusTransition $transition) use ($user, $jobPoster, $transitionManager) { |
||
| 81 | return [ |
||
| 82 | 'text' => $transition->name, |
||
| 83 | 'from_status' => $transition->from->name, |
||
| 84 | 'to_status' => $transition->to->name, |
||
| 85 | 'url' => route(WhichPortal::prefixRoute('jobs.setJobStatus'), [ |
||
| 86 | 'jobPoster' => $jobPoster, |
||
| 87 | 'status' => $transition->to->key |
||
| 88 | ]), |
||
| 89 | 'style' => array_key_exists('button_style', $transition->metadata) |
||
| 90 | ? $transition->metadata['button_style'] |
||
| 91 | : 'default', |
||
| 92 | 'disabled' => !$transitionManager->userCanTransition($user, $transition->from->key, $transition->to->key) |
||
| 93 | ]; |
||
| 94 | }; |
||
| 95 | $unclaimButton = [ |
||
| 96 | 'unclaim_job' => [ |
||
| 97 | 'text' => Lang::get('hr_advisor/job_summary.relinquish_button'), |
||
| 98 | 'url' => route('hr_advisor.jobs.unclaim', $jobPoster), |
||
| 99 | 'style' => 'stop', |
||
| 100 | 'disabled' => !$jobIsClaimed, |
||
| 101 | ] |
||
| 102 | ]; |
||
| 103 | |||
| 104 | $buttonGroups = []; |
||
| 105 | |||
| 106 | $transitionButtons = $transitionManager->legalTransitions($jobPoster->job_poster_status->key) |
||
| 107 | ->map($transitionToButton); |
||
| 108 | array_push($buttonGroups, $transitionButtons); |
||
| 109 | |||
| 110 | if (WhichPortal::isHrPortal()) { |
||
| 111 | array_push($buttonGroups, $unclaimButton); |
||
| 112 | } |
||
| 113 | |||
| 114 | $data = [ |
||
| 115 | // Localized strings. |
||
| 116 | 'summary' => $summaryLang, |
||
| 117 | 'menu' => $menuLang, |
||
| 118 | 'job_status' => $status, |
||
| 119 | 'job_status_description' => $status_description, |
||
| 120 | 'is_claimed' => $jobIsClaimed, |
||
| 121 | // User data. |
||
| 122 | 'user' => $user, |
||
| 123 | // HR Advisor data. |
||
| 124 | 'hr_advisors' => $hr_advisors, |
||
| 125 | // Job Poster data. |
||
| 126 | 'job' => $jobPoster, |
||
| 127 | // Application data. |
||
| 128 | 'applications' => $applications, |
||
| 129 | 'side_button_groups' => $buttonGroups, |
||
| 130 | 'job_review_data' => $job_review_data, |
||
| 131 | 'job_preview_data' => $job_preview_data, |
||
| 132 | 'screening_plan_data' => $screening_plan_data, |
||
| 133 | 'view_applicants_data' => $view_applicants_data, |
||
| 134 | 'portal' => $portal, |
||
| 135 | ]; |
||
| 136 | |||
| 137 | return view( |
||
| 138 | 'common/job_summary/job_summary', |
||
| 139 | $data |
||
| 140 | ); |
||
| 158 |