Passed
Push — master ( 2c3721...94fb22 )
by Grant
09:10 queued 10s
created

JobApplication   A

Complexity

Total Complexity 32

Size/Duplication

Total Lines 178
Duplicated Lines 0 %

Test Coverage

Coverage 26.76%

Importance

Changes 0
Metric Value
wmc 32
eloc 83
dl 0
loc 178
ccs 19
cts 71
cp 0.2676
rs 9.84
c 0
b 0
f 0

14 Methods

Rating   Name   Duplication   Size   Complexity  
A preferred_language() 0 2 1
A meetsEssentialCriteria() 0 15 4
A applicant_snapshot() 0 2 1
A job_poster() 0 2 1
A application_review() 0 2 1
A citizenship_declaration() 0 2 1
A veteran_status() 0 2 1
C getSectionStatus() 0 43 16
A application_status() 0 2 1
A getMeetsEssentialCriteriaAttribute() 0 3 1
A applicant() 0 2 1
A createApplicantSnapshot() 0 4 1
A skill_declarations() 0 3 1
A job_application_answers() 0 2 1
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
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 boolean $experience_saved
34
 * @property boolean $language_requirement_confirmed
35
 * @property \Jenssegers\Date\Date $created_at
36
 * @property \Jenssegers\Date\Date $updated_at
37
 *
38
 * @property \App\Models\Applicant $applicant
39
 * @property \App\Models\Applicant $applicant_snapshot
40
 * @property \App\Models\Lookup\ApplicationStatus $application_status
41
 * @property \App\Models\Lookup\CitizenshipDeclaration $citizenship_declaration
42
 * @property \App\Models\Lookup\VeteranStatus $veteran_status
43
 * @property \App\Models\Lookup\PreferredLanguage $preferred_language
44
 * @property \App\Models\JobPoster $job_poster
45
 * @property \Illuminate\Database\Eloquent\Collection $job_application_answers
46
 * @property \Illuminate\Database\Eloquent\Collection $skill_declarations
47
 * @property \App\Models\ApplicationReview $application_review
48
 */
49
class JobApplication extends BaseModel {
50
51
    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...
52
53
    protected $dispatchesEvents = [
1 ignored issue
show
introduced by
Property \App\Models\JobApplication::$dispatchesEvents does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
54
        'retrieved' => ApplicationRetrieved::class,
55
        'saved' => ApplicationSaved::class,
56
    ];
57
58
    protected $casts = [
1 ignored issue
show
introduced by
Property \App\Models\JobApplication::$casts does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
59
        'job_poster_id' => 'int',
60
        'application_status_id' => 'int',
61
        'citizenship_declaration_id' => 'int',
62
        'veteran_status_id' => 'int',
63
        'preferred_language_id' => 'int',
64
        'applicant_id' => 'int',
65
        'applicant_snapshot_id' => 'int',
66
        'submission_signature' => 'string',
67
        'submission_date' => 'string',
68
        'experience_saved' => 'boolean',
69
        'language_requirement_confirmed' => 'boolean'
70
    ];
71
    protected $fillable = [
1 ignored issue
show
introduced by
Property \App\Models\JobApplication::$fillable does not have @var annotation.
Loading history...
Coding Style Documentation introduced by
Missing member variable doc comment
Loading history...
72
        'citizenship_declaration_id',
73
        'language_requirement_confirmed',
74
        'veteran_status_id',
75
        'preferred_language_id',
76
        'submission_signature',
77
        'submission_date',
78
        'experience_saved',
79
    ];
80
81
    /**
82
     * The accessors to append to the model's array/json form.
83
     *
84
     * @var array
0 ignored issues
show
introduced by
@var annotation of property \App\Models\JobApplication::$appends does not specify type hint for its items.
Loading history...
85
     */
86
    protected $appends = ['meets_essential_criteria'];
87
88
    protected function createApplicantSnapshot($applicant_id) {
1 ignored issue
show
introduced by
Method \App\Models\JobApplication::createApplicantSnapshot() does not have parameter type hint nor @param annotation for its parameter $applicant_id.
Loading history...
introduced by
Method \App\Models\JobApplication::createApplicantSnapshot() does not have void return type hint.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function createApplicantSnapshot()
Loading history...
89
        $applicant = Applicant::where('id', $applicant_id)->firstOrFail();
90
91
        $snapshot = $applicant->replicate();
0 ignored issues
show
Unused Code introduced by
The assignment to $snapshot is dead and can be removed.
Loading history...
92
93
    }
0 ignored issues
show
Coding Style introduced by
Function closing brace must go on the next line following the body; found 1 blank lines before brace
Loading history...
94
95 1
    public function applicant() {
1 ignored issue
show
introduced by
Method \App\Models\JobApplication::applicant() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function applicant()
Loading history...
96 1
        return $this->belongsTo(\App\Models\Applicant::class);
97
    }
98
99
    public function applicant_snapshot() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::applicant_snapshot" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::applicant_snapshot() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function applicant_snapshot()
Loading history...
100
        return $this->belongsTo(\App\Models\Applicant::class, 'applicant_snapshot_id');
101
    }
102
103 12
    public function application_status() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::application_status" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::application_status() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function application_status()
Loading history...
104 12
        return $this->belongsTo(\App\Models\Lookup\ApplicationStatus::class);
105
    }
106
107
    public function citizenship_declaration() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::citizenship_declaration" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::citizenship_declaration() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function citizenship_declaration()
Loading history...
108
        return $this->belongsTo(\App\Models\Lookup\CitizenshipDeclaration::class);
109
    }
110
111
    public function veteran_status() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::veteran_status" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::veteran_status() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function veteran_status()
Loading history...
112
        return $this->belongsTo(\App\Models\Lookup\VeteranStatus::class);
113
    }
114
115
    public function preferred_language() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::preferred_language" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::preferred_language() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function preferred_language()
Loading history...
116
        return $this->belongsTo(\App\Models\Lookup\PreferredLanguage::class);
117
    }
118
119 1
    public function job_poster() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::job_poster" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::job_poster() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function job_poster()
Loading history...
120 1
        return $this->belongsTo(\App\Models\JobPoster::class);
121
    }
122
123
    public function job_application_answers() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::job_application_answers" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::job_application_answers() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function job_application_answers()
Loading history...
124
        return $this->hasMany(\App\Models\JobApplicationAnswer::class);
125
    }
126
127 1
    public function skill_declarations() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::skill_declarations" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::skill_declarations() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function skill_declarations()
Loading history...
128 1
        return $this->applicant->skill_declarations()
129 1
            ->whereIn('skill_id', $this->job_poster->criteria->pluck('skill_id'));
130
    }
131
132
    public function application_review() {
1 ignored issue
show
Coding Style introduced by
Method name "JobApplication::application_review" is not in camel caps format
Loading history...
introduced by
Method \App\Models\JobApplication::application_review() does not have return type hint nor @return annotation for its return value.
Loading history...
Coding Style Documentation introduced by
Missing doc comment for function application_review()
Loading history...
133
        return $this->hasOne(ApplicationReview::class);
134
    }
135
136
    /**
137
     * Return either 'complete', 'incomplete' or 'error', depending on the
138
     * status of the requested section.
139
     *
140
     * @param  string $section Should be one of:
1 ignored issue
show
Coding Style Documentation introduced by
Parameter comment must end with a full stop
Loading history...
141
     *                              'basics'
142
     *                              'experience'
143
     *                              'essential_skills'
144
     *                              'asset_skills'
145
     *                              'preview'
146
     *
147
     * @return string $status   'complete', 'incomplete' or 'error'
148
     */
149
    public function getSectionStatus(string $section) {
0 ignored issues
show
introduced by
Method \App\Models\JobApplication::getSectionStatus() does not have return type hint for its return value but it should be possible to add it based on @return annotation "string".
Loading history...
150
        //TODO: determine whether sections are complete or invalid
151
        $validator = new ApplicationValidator();
152
        $status = 'incomplete';
153
        switch($section) {
0 ignored issues
show
Coding Style introduced by
Expected 1 space(s) after SWITCH keyword; 0 found
Loading history...
154
            case 'basics':
155
                if ($validator->basicsComplete($this)) {
156
                    $status = 'complete';
157
                }
158
                break;
159
            case 'experience':
160
                if ($validator->experienceComplete($this)) {
161
                    $status = 'complete';
162
                }
163
                break;
164
            case 'essential_skills':
165
                if ($validator->essentialSkillsComplete($this)) {
166
                    $status = 'complete';
167
                }
168
                break;
169
            case 'asset_skills':
170
                if ($validator->assetSkillsComplete($this)) {
171
                    $status = 'complete';
172
                }
173
                break;
174
            case 'preview':
175
                if ($validator->basicsComplete($this) &&
176
                    $validator->experienceComplete($this) &&
177
                    $validator->essentialSkillsComplete($this) &&
178
                    $validator->assetSkillsComplete($this)) {
179
                    $status = 'complete';
180
                }
181
                break;
182
            case 'confirm':
183
                if ($validator->affirmationComplete($this)) {
184
                    $status = 'complete';
185
                }
186
                break;
187
            default:
188
                $status = 'error';
189
                break;
190
        }
191
        return $status;
192
    }
193
194
    /**
195
     * Returns true if this application meets all the essential criteria.
196
     * That means it has attached an SkillDeclaration for each essential criterion,
197
     * with a level at least as high as the required level.
198
     *
199
     * @return boolean
200
     */
201 1
    public function meetsEssentialCriteria(): bool
202
    {
203 1
        $essentialCriteria = $this->job_poster->criteria->filter(
204
            function ($value, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed. ( Ignorable by Annotation )

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

204
            function ($value, /** @scrutinizer ignore-unused */ $key) {

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
205 1
                return $value->criteria_type->name == 'essential';
206 1
            }
207
        );
208 1
        foreach ($essentialCriteria as $criterion) {
209 1
            $skillDeclaration = $this->skill_declarations->where("skill_id", $criterion->skill_id)->first();
210 1
            if ($skillDeclaration === null ||
211 1
                $skillDeclaration->skill_level_id < $criterion->skill_level_id) {
212 1
                return false;
213
            }
214
        }
215 1
        return true;
216
    }
217
218
    /**
219
     * Accessor for meetsEssentialCriteria function, which
220
     * allows this value to be automtacially appended to array/json representation.
221
     *
222
     * @return boolean
223
     */
224
    public function getMeetsEssentialCriteriaAttribute():bool
225
    {
226
        return $this->meetsEssentialCriteria();
227
    }
228
}
229