Conditions | 9 |
Paths | 4 |
Total Lines | 55 |
Code Lines | 33 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 2 | 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 |
||
19 | public function show(JobApplication $jobApplication, string $requestedStep = null) |
||
20 | { |
||
21 | $jobApplicationSteps = $jobApplication->jobApplicationSteps(); |
||
22 | $stepOrder = [ |
||
23 | 'basic', |
||
24 | 'experience', |
||
25 | 'skills', |
||
26 | 'fit', |
||
27 | 'review', |
||
28 | 'submission' |
||
29 | ]; |
||
30 | |||
31 | $lastTouchedStep = function () use ($stepOrder, $jobApplicationSteps) { |
||
32 | $reversedStepOrder = array_reverse($stepOrder); |
||
33 | foreach ($reversedStepOrder as $step) { |
||
34 | if ($jobApplicationSteps[$step] === 'complete' || |
||
35 | $jobApplicationSteps[$step] === 'error' |
||
36 | ) { |
||
37 | return $step; |
||
38 | } |
||
39 | } |
||
40 | |||
41 | return 'welcome'; |
||
42 | }; |
||
43 | |||
44 | if ($requestedStep === 'welcome') { |
||
45 | return view('applicant/application-timeline-root') |
||
|
|||
46 | ->with([ |
||
47 | 'title' => $jobApplication->job_poster->title, // TODO: Check with design what the title should be. |
||
48 | 'disable_clone_js' => true, |
||
49 | ]); |
||
50 | } |
||
51 | |||
52 | if ($requestedStep !== null) { |
||
53 | // Show the requested step if it has been touched before. |
||
54 | // Else, redirect the user to the last touched step. |
||
55 | // If no step has been touched, then take them to welcome step. |
||
56 | if (array_key_exists($requestedStep, $jobApplicationSteps) && |
||
57 | ($jobApplicationSteps[$requestedStep] === 'complete' || $jobApplicationSteps[$requestedStep] === 'error') |
||
58 | ) { |
||
59 | return view('applicant/application-timeline-root') |
||
60 | ->with([ |
||
61 | 'title' => $jobApplication->job_poster->title, // TODO: Check with design what the title should be. |
||
62 | 'disable_clone_js' => true, |
||
63 | ]); |
||
64 | } else { |
||
65 | return redirect( |
||
66 | route('applications.show.step', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep()]) |
||
67 | ); |
||
68 | } |
||
69 | } else { |
||
70 | // If no step has been entered (/application/id) then redirect user to the last touched step. |
||
71 | // If no step has been touched, then take them to welcome step. |
||
72 | return redirect( |
||
73 | route('applications.show.step', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep()]) |
||
74 | ); |
||
105 |