| Conditions | 16 |
| Paths | 168 |
| Total Lines | 170 |
| Code Lines | 121 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 131 | public function show(Request $request, JobPoster $jobPoster) |
||
| 132 | { |
||
| 133 | $jobPoster->load([ |
||
| 134 | 'department', |
||
| 135 | 'criteria.skill.skill_type', |
||
| 136 | 'manager.team_culture', |
||
| 137 | 'manager.work_environment' |
||
| 138 | ]); |
||
| 139 | |||
| 140 | $user = Auth::user(); |
||
| 141 | |||
| 142 | // TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model. |
||
| 143 | $workplacePhotos = []; |
||
| 144 | foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) { |
||
| 145 | $workplacePhotos[] = [ |
||
| 146 | 'description' => $photoCaption->description, |
||
| 147 | 'url' => '/images/user.png' |
||
| 148 | ]; |
||
| 149 | } |
||
| 150 | |||
| 151 | // TODO: replace route('manager.show',manager.id) in templates with link using slug. |
||
| 152 | $essential = $jobPoster->criteria->filter( |
||
| 153 | function ($value, $key) { |
||
| 154 | return $value->criteria_type->name == 'essential'; |
||
| 155 | } |
||
| 156 | )->sortBy('id'); |
||
| 157 | $asset = $jobPoster->criteria->filter( |
||
| 158 | function ($value, $key) { |
||
| 159 | return $value->criteria_type->name == 'asset'; |
||
| 160 | } |
||
| 161 | )->sortBy('id'); |
||
| 162 | $criteria = [ |
||
| 163 | 'essential' => $essential, |
||
| 164 | 'asset' => $asset, |
||
| 165 | ]; |
||
| 166 | |||
| 167 | $jobLang = Lang::get('applicant/job_post'); |
||
| 168 | |||
| 169 | $skillsLang = Lang::get('common/skills'); |
||
| 170 | |||
| 171 | $skillsArray = []; |
||
| 172 | foreach ($essential as $criterion_type => $criterion) { |
||
| 173 | $skillsArray[] = [ |
||
| 174 | 'skill' => $criterion['skill']['name'], |
||
| 175 | 'level' => $skillsLang['skill_levels'][$criterion |
||
| 176 | ->skill->skill_type->name][$criterion->skill_level->name], |
||
| 177 | ]; |
||
| 178 | } |
||
| 179 | foreach ($asset as $criterion_type => $criterion) { |
||
| 180 | $skillsArray[] = [ |
||
| 181 | 'skill' => $criterion['skill']['name'], |
||
| 182 | 'level' => $skillsLang['skill_levels'][$criterion |
||
| 183 | ->skill->skill_type->name][$criterion->skill_level->name], |
||
| 184 | ]; |
||
| 185 | } |
||
| 186 | |||
| 187 | $applyButton = []; |
||
| 188 | if (WhichPortal::isManagerPortal()) { |
||
| 189 | $applyButton = [ |
||
| 190 | 'href' => route('manager.jobs.edit', $jobPoster->id), |
||
| 191 | 'title' => $jobLang['apply']['edit_link_title'], |
||
| 192 | 'text' => $jobLang['apply']['edit_link_label'], |
||
| 193 | ]; |
||
| 194 | } elseif (WhichPortal::isHrPortal()) { |
||
| 195 | if ($jobPoster->hr_advisors->contains('user_id', $user->id)) { |
||
| 196 | $applyButton = [ |
||
| 197 | 'href' => route('hr_advisor.jobs.summary', $jobPoster->id), |
||
| 198 | 'title' => null, |
||
| 199 | 'text' => Lang::get('hr_advisor/job_summary.summary_title'), |
||
| 200 | ]; |
||
| 201 | } else { |
||
| 202 | $applyButton = [ |
||
| 203 | 'href' => route('hr_advisor.jobs.index'), |
||
| 204 | 'title' => null, |
||
| 205 | 'text' => Lang::get('hr_advisor/job_index.title'), |
||
| 206 | ]; |
||
| 207 | } |
||
| 208 | } elseif (Auth::check() && $jobPoster->isOpen()) { |
||
| 209 | $application = JobApplication::where('applicant_id', Auth::user()->applicant->id) |
||
| 210 | ->where('job_poster_id', $jobPoster->id)->first(); |
||
| 211 | // If applicants job application is not draft anymore then link to application preview page. |
||
| 212 | if ($application != null && $application->application_status->name != 'draft') { |
||
| 213 | $applyButton = [ |
||
| 214 | 'href' => route('applications.show', $application->id), |
||
| 215 | 'title' => $jobLang['apply']['view_link_title'], |
||
| 216 | 'text' => $jobLang['apply']['view_link_label'], |
||
| 217 | ]; |
||
| 218 | } else { |
||
| 219 | $applyButton = [ |
||
| 220 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
| 221 | 'title' => $jobLang['apply']['apply_link_title'], |
||
| 222 | 'text' => $jobLang['apply']['apply_link_label'], |
||
| 223 | ]; |
||
| 224 | } |
||
| 225 | } elseif (Auth::guest() && $jobPoster->isOpen()) { |
||
| 226 | $applyButton = [ |
||
| 227 | 'href' => route('job.application.edit.1', $jobPoster->id), |
||
| 228 | 'title' => $jobLang['apply']['login_link_title'], |
||
| 229 | 'text' => $jobLang['apply']['login_link_label'], |
||
| 230 | ]; |
||
| 231 | } else { |
||
| 232 | $applyButton = [ |
||
| 233 | 'href' => null, |
||
| 234 | 'title' => null, |
||
| 235 | 'text' => $jobLang['apply']['job_closed_label'], |
||
| 236 | ]; |
||
| 237 | } |
||
| 238 | |||
| 239 | $jpb_release_date = strtotime('2019-08-21 16:18:17'); |
||
| 240 | $job_created_at = strtotime($jobPoster->created_at); |
||
| 241 | |||
| 242 | $custom_breadcrumbs = [ |
||
| 243 | 'home' => route('home'), |
||
| 244 | 'jobs' => route(WhichPortal::prefixRoute('jobs.index')), |
||
| 245 | $jobPoster->title ?: 'job-title-missing' => route(WhichPortal::prefixRoute('jobs.summary'), $jobPoster), |
||
| 246 | 'preview' => '', |
||
| 247 | ]; |
||
| 248 | |||
| 249 | // If the poster is part of the Strategic Talent Response dept, use the talent stream template. |
||
| 250 | // Else, If the job poster is created after the release of the JPB. |
||
| 251 | // Then, render with updated poster template. |
||
| 252 | // Else, render with old poster template. |
||
| 253 | if ($jobPoster->isInStrategicResponseDepartment()) { |
||
| 254 | return view( |
||
| 255 | 'applicant/strategic_response_job_post', |
||
| 256 | [ |
||
| 257 | 'job_post' => $jobLang, |
||
| 258 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 259 | 'skill_template' => $skillsLang, |
||
| 260 | 'job' => $jobPoster, |
||
| 261 | 'manager' => $jobPoster->manager, |
||
| 262 | 'criteria' => $criteria, |
||
| 263 | 'apply_button' => $applyButton, |
||
| 264 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
| 265 | ] |
||
| 266 | ); |
||
| 267 | } elseif ($job_created_at > $jpb_release_date) { |
||
| 268 | // Updated job poster (JPB). |
||
| 269 | return view( |
||
| 270 | 'applicant/jpb_job_post', |
||
| 271 | [ |
||
| 272 | 'job_post' => $jobLang, |
||
| 273 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 274 | 'skill_template' => $skillsLang, |
||
| 275 | 'job' => $jobPoster, |
||
| 276 | 'manager' => $jobPoster->manager, |
||
| 277 | 'criteria' => $criteria, |
||
| 278 | 'apply_button' => $applyButton, |
||
| 279 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
| 280 | 'skills' => $skillsArray, |
||
| 281 | 'goc' => Lang::get('common/goc'), |
||
| 282 | ] |
||
| 283 | ); |
||
| 284 | } else { |
||
| 285 | // Old job poster. |
||
| 286 | return view( |
||
| 287 | 'applicant/job_post', |
||
| 288 | [ |
||
| 289 | 'job_post' => $jobLang, |
||
| 290 | 'frequencies' => Lang::get('common/lookup/frequency'), |
||
| 291 | 'manager' => $jobPoster->manager, |
||
| 292 | 'manager_profile_photo_url' => '/images/user.png', // TODO get real photo. |
||
| 293 | 'team_culture' => $jobPoster->manager->team_culture, |
||
| 294 | 'work_environment' => $jobPoster->manager->work_environment, |
||
| 295 | 'workplace_photos' => $workplacePhotos, |
||
| 296 | 'job' => $jobPoster, |
||
| 297 | 'criteria' => $criteria, |
||
| 298 | 'apply_button' => $applyButton, |
||
| 299 | 'skill_template' => Lang::get('common/skills'), |
||
| 300 | 'custom_breadcrumbs' => $custom_breadcrumbs, |
||
| 301 | ] |
||
| 498 |