Passed
Push — task/application-touch-step-st... ( 8f1a36...136542 )
by Yonathan
07:42 queued 02:55
created

ApplicationTimelineController::complete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 11
c 0
b 0
f 0
dl 0
loc 17
rs 9.9
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Http\Controllers;
4
5
use App\Http\Controllers\Controller;
6
use App\Models\JobApplication;
7
use App\Models\JobPoster;
8
use Illuminate\Support\Facades\Auth;
9
use Illuminate\Support\Facades\Lang;
10
11
class ApplicationTimelineController extends Controller
12
{
13
    /**
14
     * Display job application.
15
     *
16
     * @param  \App\Models\JobApplication $application Incoming Application object.
17
     * @return \Illuminate\Http\Response
18
    */
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')
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

45
            return /** @scrutinizer ignore-call */ view('applicant/application-timeline-root')
Loading history...
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(
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

65
                return /** @scrutinizer ignore-call */ redirect(
Loading history...
66
                    route('applications.show.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

66
                    /** @scrutinizer ignore-call */ 
67
                    route('applications.show.step', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep()])
Loading history...
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
            );
75
        }
76
    }
77
78
    /**
79
     * Show the congrats page after application it's validated and submit.
80
     *
81
     * @param  \App\Models\JobPoster $jobPoster Incoming Job Poster object.
82
     * @return \Illuminate\Http\Response
83
     */
84
    public function complete(/* JobPoster $jobPoster */)
85
    {
86
        // Dummy Data.
87
        $applicant = Auth::user()->applicant;
88
        $jobPoster = JobPoster::where('job_poster_status_id', '10')->first();
89
        $application = JobApplication::where('job_poster_id', $jobPoster->id)->first();
90
91
        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

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