| Conditions | 9 |
| Paths | 4 |
| Total Lines | 65 |
| Code Lines | 40 |
| 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 |
||
| 18 | public function show(JobApplication $application, string $requestedStep = null) |
||
| 19 | { |
||
| 20 | $jobApplicationSteps = $application->jobApplicationSteps(); |
||
| 21 | $stepOrder = [ |
||
| 22 | 'basic', |
||
| 23 | 'experience', |
||
| 24 | 'skills', |
||
| 25 | 'fit', |
||
| 26 | 'review', |
||
| 27 | 'submission' |
||
| 28 | ]; |
||
| 29 | |||
| 30 | $lastTouchedStep = function () use ($stepOrder, $jobApplicationSteps) { |
||
| 31 | $reversedStepOrder = array_reverse($stepOrder); |
||
| 32 | foreach ($reversedStepOrder as $step) { |
||
| 33 | if ($jobApplicationSteps[$step] === 'complete' || |
||
| 34 | $jobApplicationSteps[$step] === 'error' |
||
| 35 | ) { |
||
| 36 | return $step; |
||
| 37 | } |
||
| 38 | } |
||
| 39 | |||
| 40 | return 'welcome'; |
||
| 41 | }; |
||
| 42 | |||
| 43 | $customBreadcrumbs = [ |
||
| 44 | 'home' => route('home'), |
||
|
|
|||
| 45 | 'applications' => route('applications.index'), |
||
| 46 | $application->job_poster->title => route('jobs.summary', ['jobPoster' => $application->job_poster]), |
||
| 47 | Lang::get('common/breadcrumbs.application_id', ['id' => $application->id]) => '', |
||
| 48 | ]; |
||
| 49 | |||
| 50 | |||
| 51 | if ($requestedStep === 'welcome') { |
||
| 52 | return view('applicant/application-timeline-root') |
||
| 53 | ->with([ |
||
| 54 | 'title' => $application->job_poster->title, |
||
| 55 | 'disable_clone_js' => true, |
||
| 56 | 'custom_breadcrumbs' => $customBreadcrumbs, |
||
| 57 | ]); |
||
| 58 | } |
||
| 59 | |||
| 60 | if ($requestedStep !== null) { |
||
| 61 | // Show the requested step if it has been touched before. |
||
| 62 | // Else, redirect the user to the last touched step. |
||
| 63 | // If no step has been touched, then take them to welcome step. |
||
| 64 | if (array_key_exists($requestedStep, $jobApplicationSteps) && |
||
| 65 | ($jobApplicationSteps[$requestedStep] === 'complete' || $jobApplicationSteps[$requestedStep] === 'error') |
||
| 66 | ) { |
||
| 67 | return view('applicant/application-timeline-root') |
||
| 68 | ->with([ |
||
| 69 | 'title' => $application->job_poster->title, |
||
| 70 | 'disable_clone_js' => true, |
||
| 71 | 'custom_breadcrumbs' => $customBreadcrumbs, |
||
| 72 | ]); |
||
| 73 | } else { |
||
| 74 | return redirect( |
||
| 75 | route('applications.timeline.step', ['application' => $application, 'step' => $lastTouchedStep()]) |
||
| 76 | ); |
||
| 77 | } |
||
| 78 | } else { |
||
| 79 | // If no step has been entered (/application/id) then redirect user to the last touched step. |
||
| 80 | // If no step has been touched, then take them to welcome step. |
||
| 81 | return redirect( |
||
| 82 | route('applications.timeline.step', ['application' => $application, 'step' => $lastTouchedStep()]) |
||
| 83 | ); |
||
| 113 |