Passed
Push — task/application-handle-step-s... ( 5a9035...2b5b8c )
by Yonathan
04:05
created

ApplicationTimelineController::show()   B

Complexity

Conditions 8
Paths 4

Size

Total Lines 44
Code Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 2 Features 0
Metric Value
eloc 26
dl 0
loc 44
rs 8.4444
c 3
b 2
f 0
cc 8
nc 4
nop 2
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\Log;
9
use Illuminate\Support\Facades\Request;
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 $step = null)
20
    {
21
        $requestedStep = $step;
22
        $jobApplicationSteps = $jobApplication->jobApplicationSteps();
23
        $stepOrder = [
24
            'basic',
25
            'experience',
26
            'skills-intro' => 'skills',
27
            'skills',
28
            'fit',
29
            'review',
30
            'submission'
31
        ];
32
33
34
        // If the applicant has previously reached the requested step
35
        // then return them to the step.
36
37
        if (
38
            $requestedStep !== null &&
39
            array_key_exists($requestedStep, $jobApplicationSteps) &&
40
            ($jobApplicationSteps[$requestedStep] === 'complete' || $jobApplicationSteps[$requestedStep] === 'error')
41
        ) {
42
            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

42
            return /** @scrutinizer ignore-call */ view('applicant/application-timeline-root')
Loading history...
43
            ->with([
44
                'title' => $jobApplication->job_poster->title, // TODO: Check with design what the title should be.
45
                'disable_clone_js' => true,
46
            ]);
47
        }
48
49
        // If the applicant has not reached the requested step
50
        // in the application then redirect back to last touched step.
51
        $reversedStepOrder = array_reverse($stepOrder);
52
        foreach ($reversedStepOrder as $lastTouchedStep) {
53
            if ($jobApplicationSteps[$lastTouchedStep] === 'complete' || $jobApplicationSteps[$lastTouchedStep] === 'error') {
54
                return redirect()->route('application.timeline', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep]);
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

54
                return /** @scrutinizer ignore-call */ redirect()->route('application.timeline', ['jobApplication' => $jobApplication, 'step' => $lastTouchedStep]);
Loading history...
55
            }
56
        }
57
58
        // If no step has been reached yet it will take applicant to welcome step.
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
    }
65
}
66