Passed
Push — feature/ie-alert ( c39468...dc7a98 )
by
unknown
07:35
created

ApplicationTimelineController::show()   B

Complexity

Conditions 9
Paths 4

Size

Total Lines 55
Code Lines 33

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 33
c 0
b 0
f 0
dl 0
loc 55
rs 8.0555
cc 9
nc 4
nop 2

How to fix   Long Method   

Long Method

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:

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\JobApplication;
7
use Illuminate\Support\Facades\Lang;
8
9
class ApplicationTimelineController extends Controller
10
{
11
    /**
12
     * Display job application.
13
     *
14
     * @param  \App\Models\JobApplication $application Incoming Application object.
15
     * @return \Illuminate\Http\Response
16
    */
17
    public function show(JobApplication $jobApplication, string $requestedStep = null)
18
    {
19
        $jobApplicationSteps = $jobApplication->jobApplicationSteps();
20
        $stepOrder = [
21
            'basic',
22
            'experience',
23
            'skills',
24
            'fit',
25
            'review',
26
            'submission'
27
        ];
28
29
        $lastTouchedStep = function () use ($stepOrder, $jobApplicationSteps) {
30
            $reversedStepOrder = array_reverse($stepOrder);
31
            foreach ($reversedStepOrder as $step) {
32
                if ($jobApplicationSteps[$step] === 'complete' ||
33
                    $jobApplicationSteps[$step] === 'error'
34
                ) {
35
                    return $step;
36
                }
37
            }
38
39
            return 'welcome';
40
        };
41
42
        if ($requestedStep === 'welcome') {
43
            return view('applicant/application-timeline-root')
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

43
            return /** @scrutinizer ignore-call */ view('applicant/application-timeline-root')
Loading history...
44
                ->with([
45
                    'title' => $jobApplication->job_poster->title, // TODO: Check with design what the title should be.
46
                    'disable_clone_js' => true,
47
                ]);
48
        }
49
50
        if ($requestedStep !== null) {
51
            // Show the requested step if it has been touched before.
52
            // Else, redirect the user to the last touched step.
53
            // If no step has been touched, then take them to welcome step.
54
            if (array_key_exists($requestedStep, $jobApplicationSteps) &&
55
                ($jobApplicationSteps[$requestedStep] === 'complete' || $jobApplicationSteps[$requestedStep] === 'error')
56
            ) {
57
                return view('applicant/application-timeline-root')
58
                ->with([
59
                    'title' => $jobApplication->job_poster->title, // TODO: Check with design what the title should be.
60
                    'disable_clone_js' => true,
61
                ]);
62
            } else {
63
                return redirect(
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

63
                return /** @scrutinizer ignore-call */ redirect(
Loading history...
64
                    route('applications.timeline.step', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep()])
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

64
                    /** @scrutinizer ignore-call */ 
65
                    route('applications.timeline.step', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep()])
Loading history...
65
                );
66
            }
67
        } else {
68
            // If no step has been entered (/application/id) then redirect user to the last touched step.
69
            // If no step has been touched, then take them to welcome step.
70
            return redirect(
71
                route('applications.timeline.step', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep()])
72
            );
73
        }
74
    }
75
76
    /**
77
     * Show the congrats page after application it's validated and submit.
78
     *
79
     * @param  \App\Models\JobApplication $jobApplication Incoming Job Application object.
80
     * @return \Illuminate\Http\Response
81
     */
82
    public function complete(JobApplication $jobApplication)
83
    {
84
        // Dummy Data.
85
        $applicant = $jobApplication->applicant;
86
        $jobPoster = $jobApplication->job_poster;
87
88
        return view(
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
        return /** @scrutinizer ignore-call */ view(
Loading history...
89
            'applicant/application/congrats',
90
            [
91
                'applicant' => $applicant,
92
                'application' => $jobApplication,
93
                'application_template' => Lang::get(
94
                    'applicant/application_template',
95
                    ['security_clearance' => $jobPoster->security_clearance->value ]
96
                ),
97
                'jobPoster' => $jobPoster,
98
            ]
99
        );
100
    }
101
}
102