Completed
Push — feature/application_tracker_va... ( b50c96...fa2127 )
by Tristan
16:42 queued 09:45
created

JobApplication::skill_declarations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

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