Completed
Push — feature/application_tracker_va... ( bb4b6b )
by Tristan
18:27 queued 08:29
created

JobApplication::getSectionStatus()   B

Complexity

Conditions 7
Paths 7

Size

Total Lines 23
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
eloc 19
dl 0
loc 23
ccs 0
cts 18
cp 0
rs 8.8333
c 0
b 0
f 0
cc 7
nc 7
nop 1
crap 56
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
0 ignored issues
show
Coding Style introduced by
Missing @link tag in file comment
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
7
8
namespace App\Models;
9
use App\Models\Lookup\VeteranStatus;
10
use App\Models\Lookup\PreferredLanguage;
11
use App\Models\Lookup\CitizenshipDeclaration;
12
use App\Models\ApplicationReview;
13
use Illuminate\Notifications\Notifiable;
14
use App\Events\ApplicationSaved;
15
use App\Events\ApplicationRetrieved;
16
use App\Services\Validation\ApplicationValidator;
17
18
/**
19
 * Class JobApplication
20
 *
21
 * @property int $id
22
 * @property int $job_poster_id
23
 * @property int $application_status_id
24
 * @property int $citizenship_declaration_id
25
 * @property int $veteran_status_id
26
 * @property int $preferred_language_id
27
 * @property int $applicant_id
28
 * @property int $applicant_snapshot_id
29
 * @property string $submission_signature
30
 * @property string $submission_date
31
 * @property \Jenssegers\Date\Date $created_at
32
 * @property \Jenssegers\Date\Date $updated_at
33
 *
34
 * @property \App\Models\Applicant $applicant
35
 * @property \App\Models\Applicant $applicant_snapshot
36
 * @property \App\Models\Lookup\ApplicationStatus $application_status
37
 * @property \App\Models\Lookup\CitizenshipDeclaration $citizenship_declaration
38
 * @property \App\Models\Lookup\VeteranStatus $veteran_status
39
 * @property \App\Models\Lookup\PreferredLanguage $preferred_language
40
 * @property \App\Models\JobPoster $job_poster
41
 * @property \Illuminate\Database\Eloquent\Collection $job_application_answers
42
 * @property \Illuminate\Database\Eloquent\Collection $skill_declarations
43
 * @property \App\Models\ApplicationReview $application_review
44
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
45
class JobApplication extends BaseModel {
0 ignored issues
show
Coding Style introduced by
Opening brace of a class must be on the line after the definition
Loading history...
46
47
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\Models\JobApplication: $email, $phone_number
Loading history...
48
49
    protected $dispatchesEvents = [
50
        'retrieved' => ApplicationRetrieved::class,
51
        'saved' => ApplicationSaved::class,
52
    ];
53
54
    protected $casts = [
55
        'job_poster_id' => 'int',
56
        'application_status_id' => 'int',
57
        'citizenship_declaration_id' => 'int',
58
        'veteran_status_id' => 'int',
59
        'preferred_language_id' => 'int',
60
        'applicant_id' => 'int',
61
        'applicant_snapshot_id' => 'int',
62
        'submission_signature' => 'string',
63
        'submission_date' => 'string',
64
    ];
65
    protected $fillable = [
66
        'citizenship_declaration_id',
67
        'veteran_status_id',
68
        'preferred_language_id',
69
        'submission_signature',
70
        'submission_date',
71
    ];
72
73
    protected function createApplicantSnapshot($applicant_id) {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function createApplicantSnapshot()
Loading history...
74
        $applicant = Applicant::where('id', $applicant_id)->firstOrFail();
75
76
        $snapshot = $applicant->replicate();
0 ignored issues
show
Unused Code introduced by
The assignment to $snapshot is dead and can be removed.
Loading history...
77
78
    }
79
80
    public function applicant() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function applicant()
Loading history...
81
        return $this->belongsTo(\App\Models\Applicant::class);
82
    }
83
84
    public function applicant_snapshot() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function applicant_snapshot()
Loading history...
Coding Style introduced by
Public method name "JobApplication::applicant_snapshot" is not in camel caps format
Loading history...
85
        return $this->belongsTo(\App\Models\Applicant::class, 'applicant_snapshot_id');
86
    }
87
88
    public function application_status() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function application_status()
Loading history...
Coding Style introduced by
Public method name "JobApplication::application_status" is not in camel caps format
Loading history...
89
        return $this->belongsTo(\App\Models\Lookup\ApplicationStatus::class);
90
    }
91
92
    public function citizenship_declaration() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function citizenship_declaration()
Loading history...
Coding Style introduced by
Public method name "JobApplication::citizenship_declaration" is not in camel caps format
Loading history...
93
        return $this->belongsTo(\App\Models\Lookup\CitizenshipDeclaration::class);
94
    }
95
96
    public function veteran_status() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function veteran_status()
Loading history...
Coding Style introduced by
Public method name "JobApplication::veteran_status" is not in camel caps format
Loading history...
97
        return $this->belongsTo(\App\Models\Lookup\VeteranStatus::class);
98
    }
99
100
    public function preferred_language() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function preferred_language()
Loading history...
Coding Style introduced by
Public method name "JobApplication::preferred_language" is not in camel caps format
Loading history...
101
        return $this->belongsTo(\App\Models\Lookup\PreferredLanguage::class);
102
    }
103
104
    public function job_poster() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_poster()
Loading history...
Coding Style introduced by
Public method name "JobApplication::job_poster" is not in camel caps format
Loading history...
105
        return $this->belongsTo(\App\Models\JobPoster::class);
106
    }
107
108
    public function job_application_answers() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_application_answers()
Loading history...
Coding Style introduced by
Public method name "JobApplication::job_application_answers" is not in camel caps format
Loading history...
109
        return $this->hasMany(\App\Models\JobApplicationAnswer::class);
110
    }
111
112
    public function application_review() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function application_review()
Loading history...
Coding Style introduced by
Public method name "JobApplication::application_review" is not in camel caps format
Loading history...
113
        return $this->hasOne(ApplicationReview::class);
114
    }
115
116
    /**
117
     * Return either 'complete', 'incomplete' or 'error', depending on the
118
     * status of the requested section.
119
     *
120
     * @param  string $section Should be one of:
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 1 spaces but found 2
Loading history...
121
     *                              'basics'
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 30
Loading history...
122
     *                              'experience'
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 30
Loading history...
123
     *                              'essential_skills'
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 30
Loading history...
124
     *                              'asset_skills'
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 30
Loading history...
125
     *                              'preview'
0 ignored issues
show
Coding Style introduced by
Parameter comment not aligned correctly; expected 25 spaces but found 30
Loading history...
126
     *
127
     * @return string $status   'complete', 'incomplete' or 'error'
128
     */
129
    public function getSectionStatus(string $section) {
130
        //TODO: determine whether sections are complete or invalid
131
        $validator = new ApplicationValidator();
132
        $status = 'incomplete';
133
        switch($section) {
134
            case 'basics':
135
                if ($validator->basicsComplete($this)) {
136
                    $status = 'complete';
137
                }
138
                break;
139
            case 'experience':
140
                break;
141
            case 'essential_skills':
142
                break;
143
            case 'asset_skills':
144
                break;
145
            case 'preview':
146
                break;
147
            default:
148
                $status = 'error';
149
                break;
150
        }
151
        return $status;
152
    }
153
}
154