| Conditions | 12 |
| Paths | 28 |
| Total Lines | 124 |
| Code Lines | 85 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 125 | public function show(Request $request, JobPoster $jobPoster) |
||
| 126 | { |
||
| 127 | $jobPoster->load([ |
||
| 128 | 'department', |
||
| 129 | 'criteria.skill.skill_type', |
||
| 130 | 'manager.team_culture', |
||
| 131 | 'manager.work_environment' |
||
| 132 | ]); |
||
| 133 | |||
| 134 | $user = Auth::user(); |
||
| 135 | |||
| 136 | // TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model. |
||
| 137 | $workplacePhotos = []; |
||
| 138 | foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
||
| 139 | $workplacePhotos[] = [ |
||
| 140 | 'description' => $photoCaption->description, |
||
| 141 | 'url' => '/images/user.png' |
||
| 142 | ]; |
||
| 143 | } |
||
| 144 | |||
| 145 | // TODO: replace route('manager.show',manager.id) in templates with link using slug. |
||
| 146 | $criteria = [ |
||
| 147 | 'essential' => $jobPoster->criteria->filter( |
||
| 148 | function ($value, $key) { |
||
| 149 | return $value->criteria_type->name == 'essential'; |
||
| 150 | } |
||
| 151 | ), |
||
| 152 | 'asset' => $jobPoster->criteria->filter( |
||
| 153 | function ($value, $key) { |
||
| 154 | return $value->criteria_type->name == 'asset'; |
||
| 155 | } |
||
| 156 | ), |
||
| 157 | ]; |
||
| 158 | |||
| 159 | $jobLang = Lang::get('applicant/job_post'); |
||
| 160 | |||
| 161 | $applyButton = []; |
||
| 162 | if (WhichPortal::isManagerPortal()) { |
||
| 163 | $applyButton = [ |
||
| 164 | 'href' => route('manager.jobs.edit', $jobPoster->id), |
||
| 165 | 'title' => $jobLang['apply']['edit_link_title'], |
||
| 166 | 'text' => $jobLang['apply']['edit_link_label'], |
||
| 167 | ]; |
||
| 168 | } elseif (WhichPortal::isHrPortal()) { |
||
| 169 | if ($jobPoster->hr_advisors->contains('user_id', $user->id)) { |
||
| 170 | $applyButton = [ |
||
| 171 | 'href' => route('hr_advisor.jobs.summary', $jobPoster->id), |
||
| 172 | 'title' => null, |
||
| 173 | 'text' => Lang::get('hr_advisor/job_summary.summary_title'), |
||
| 174 | ]; |
||
| 175 | } else { |
||
| 176 | $applyButton = [ |
||
| 177 | 'href' => route('hr_advisor.jobs.index'), |
||
| 178 | 'title' => null, |
||
| 179 | 'text' => Lang::get('hr_advisor/job_index.title'), |
||
| 180 | ]; |
||
| 181 | } |
||
| 182 | } elseif (Auth::check() && $jobPoster->isOpen()) { |
||
| 183 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
| 184 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
| 185 | // If applicants job application is not draft anymore then link to application preview page. |
||
| 186 | if ($application != null && $application->application_status->name != 'draft') { |
||
| 187 | $applyButton = [ |
||
| 188 | 'href' => route('applications.show', $application->id), |
||
| 189 | 'title' => $jobLang['apply']['view_link_title'], |
||
| 190 | 'text' => $jobLang['apply']['view_link_label'], |
||
| 191 | ]; |
||
| 192 | } else { |
||
| 193 | $applyButton = [ |
||
| 194 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
| 195 | 'title' => $jobLang['apply']['apply_link_title'], |
||
| 196 | 'text' => $jobLang['apply']['apply_link_label'], |
||
| 197 | ]; |
||
| 198 | } |
||
| 199 | } elseif (Auth::guest() && $jobPoster->isOpen()) { |
||
| 200 | $applyButton = [ |
||
| 201 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
| 202 | 'title' => $jobLang['apply']['login_link_title'], |
||
| 203 | 'text' => $jobLang['apply']['login_link_label'], |
||
| 204 | ]; |
||
| 205 | } else { |
||
| 206 | $applyButton = [ |
||
| 207 | 'href' => null, |
||
| 208 | 'title' => null, |
||
| 209 | 'text' => $jobLang['apply']['job_closed_label'], |
||
| 210 | ]; |
||
| 211 | } |
||
| 212 | |||
| 213 | $jpb_release_date = strtotime('2019-08-21 16:18:17'); |
||
| 214 | $job_created_at = strtotime($jobPoster->created_at); |
||
| 215 | |||
| 216 | // If the job poster is created after the release of the JPB. |
||
| 217 | // Then, render with updated poster template. |
||
| 218 | // Else, render with old poster template. |
||
| 219 | if ($job_created_at > $jpb_release_date) { |
||
| 220 | // Updated job poster (JPB). |
||
| 221 | return view( |
||
| 222 | 'applicant/jpb_job_post', |
||
| 223 | [ |
||
| 224 | 'job_post' => $jobLang, |
||
| 225 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 226 | 'skill_template' => Lang::get('common/skills'), |
||
| 227 | 'job' => $jobPoster, |
||
| 228 | 'manager' => $jobPoster->manager, |
||
| 229 | 'criteria' => $criteria, |
||
| 230 | 'apply_button' => $applyButton, |
||
| 231 | ] |
||
| 232 | ); |
||
| 233 | } else { |
||
| 234 | // Old job poster. |
||
| 235 | return view( |
||
| 236 | 'applicant/job_post', |
||
| 237 | [ |
||
| 238 | 'job_post' => $jobLang, |
||
| 239 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 240 | 'manager' => $jobPoster->manager, |
||
| 241 | 'manager_profile_photo_url' => '/images/user.png', // TODO get real photo. |
||
| 242 | 'team_culture' => $jobPoster->manager->team_culture, |
||
| 243 | 'work_environment' => $jobPoster->manager->work_environment, |
||
| 244 | 'workplace_photos' => $workplacePhotos, |
||
| 245 | 'job' => $jobPoster, |
||
| 246 | 'criteria' => $criteria, |
||
| 247 | 'apply_button' => $applyButton, |
||
| 248 | 'skill_template' => Lang::get('common/skills'), |
||
| 249 | ] |
||
| 410 |