Passed
Push — feature/manager_poster_index ( ae25c3...dfbafb )
by Xander
05:47
created

JobPoster   A

Complexity

Total Complexity 27

Size/Duplication

Total Lines 162
Duplicated Lines 0 %

Test Coverage

Coverage 82.81%

Importance

Changes 0
Metric Value
wmc 27
eloc 89
dl 0
loc 162
rs 10
c 0
b 0
f 0
ccs 53
cts 64
cp 0.8281

17 Methods

Rating   Name   Duplication   Size   Complexity  
A job_poster_translations() 0 2 1
A province() 0 2 1
A language_requirement() 0 2 1
A job_term() 0 2 1
A department() 0 2 1
A manager() 0 2 1
A criteria() 0 2 1
A submitted_applications() 0 3 1
A job_poster_questions() 0 2 1
A security_clearance() 0 2 1
A screening_plans() 0 3 1
A job_poster_key_tasks() 0 2 1
A job_applications() 0 2 1
A timeRemaining() 0 25 4
A isClosed() 0 4 3
A isOpen() 0 4 3
A status() 0 14 4
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
10
use App\Events\JobSaved;
11
use App\Models\JobApplication;
12
use Illuminate\Notifications\Notifiable;
13
use Illuminate\Support\Facades\Lang;
14
use Jenssegers\Date\Date;
15
16
/**
17
 * Class JobPoster
18
 *
19
 * @property int $id
20
 * @property int $job_term_id
21
 * @property int $term_qty
22
 * @property \Jenssegers\Date\Date $open_date_time
23
 * @property \Jenssegers\Date\Date $close_date_time
24
 * @property \Jenssegers\Date\Date $start_date_time
25
 * @property \Jenssegers\Date\Date $review_requested_at
26
 * @property int $department_id
27
 * @property int $province_id
28
 * @property int $salary_min
29
 * @property int $salary_max
30
 * @property int $noc
31
 * @property string $classification
32
 * @property int $security_clearance_id
33
 * @property int $language_requirement_id
34
 * @property boolean $remote_work_allowed
35
 * @property int $manager_id
36
 * @property boolean $published
37
 * @property \Jenssegers\Date\Date $created_at
38
 * @property \Jenssegers\Date\Date $updated_at
39
 *
40
 * @property int $submitted_applications_count
41
 *
42
 * @property \App\Models\Lookup\Department $department
43
 * @property \App\Models\Lookup\JobTerm $job_term
44
 * @property \App\Models\Lookup\LanguageRequirement $language_requirement
45
 * @property \App\Models\Manager $manager
46
 * @property \App\Models\Lookup\Province $province
47
 * @property \App\Models\Lookup\SecurityClearance $security_clearance
48
 * @property \Illuminate\Database\Eloquent\Collection $criteria
49
 * @property \Illuminate\Database\Eloquent\Collection $job_applications
50
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_key_tasks
51
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_questions
52
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_translations
53
 * @property \Illuminate\Database\Eloquent\Collection $submitted_applications
54
 * @property \Illuminate\Database\Eloquent\Collection[ScreeningPlan] $screening_plans
55
 *
56
 * Localized Properties:
57
 * @property string $city
58
 * @property string $title
59
 * @property string $impact
60
 * @property string $branch
61
 * @property string $division
62
 * @property string $education
63
 *
64
 * Methods
65
 * @method boolean isOpen()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
66
 * @method string timeRemaining()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
67
 */
0 ignored issues
show
Documentation Bug introduced by
The doc comment \Illuminate\Database\Elo...llection[ScreeningPlan] at position 1 could not be parsed: Expected ']' at position 1, but found '['.
Loading history...
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...
68
class JobPoster 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...
69
70
    use \Dimsav\Translatable\Translatable;
0 ignored issues
show
introduced by
The trait Dimsav\Translatable\Translatable requires some properties which are not provided by App\Models\JobPoster: $translations, $useTranslationFallback, $translationModel, $localeKey, $translationForeignKey
Loading history...
71
    use Notifiable;
0 ignored issues
show
introduced by
The trait Illuminate\Notifications\Notifiable requires some properties which are not provided by App\Models\JobPoster: $email, $phone_number
Loading history...
72
73
    public $translatedAttributes = ['city', 'title', 'impact', 'branch', 'division', 'education'];
74
    protected $casts = [
75
        'job_term_id' => 'int',
76
        'department_id' => 'int',
77
        'province_id' => 'int',
78
        'salary_min' => 'int',
79
        'salary_max' => 'int',
80
        'noc' => 'int',
81
        'security_clearance_id' => 'int',
82
        'language_requirement_id' => 'int',
83
        'remote_work_allowed' => 'boolean',
84
        'manager_id' => 'int',
85
        'published' => 'boolean'
86
    ];
87
    protected $dates = [
88
        'open_date_time',
89
        'close_date_time',
90
        'start_date_time',
91
        'review_requested_at'
92
    ];
93
    protected $fillable = [
94
        'job_term_id',
95
        'term_qty',
96
        'open_date_time',
97
        'close_date_time',
98
        'start_date_time',
99
        'department_id',
100
        'province_id',
101
        'salary_min',
102
        'salary_max',
103
        'noc',
104
        'classification',
105
        'security_clearance_id',
106
        'language_requirement_id',
107
        'remote_work_allowed',
108
        'published'
109
    ];
110
    protected $withCount = ['submitted_applications'];
111
112
    protected $dispatchesEvents = [
113
        'saved' => JobSaved::class,
114
    ];
115
116 6
    public function department() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function department()
Loading history...
117 6
        return $this->belongsTo(\App\Models\Lookup\Department::class);
118
    }
119
120 6
    public function job_term() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_term()
Loading history...
Coding Style introduced by
Public method name "JobPoster::job_term" is not in camel caps format
Loading history...
121 6
        return $this->belongsTo(\App\Models\Lookup\JobTerm::class);
122
    }
123
124 6
    public function language_requirement() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function language_requirement()
Loading history...
Coding Style introduced by
Public method name "JobPoster::language_requirement" is not in camel caps format
Loading history...
125 6
        return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class);
126
    }
127
128 16
    public function manager() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function manager()
Loading history...
129 16
        return $this->belongsTo(\App\Models\Manager::class);
130
    }
131
132 6
    public function province() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function province()
Loading history...
133 6
        return $this->belongsTo(\App\Models\Lookup\Province::class);
134
    }
135
136 6
    public function security_clearance() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function security_clearance()
Loading history...
Coding Style introduced by
Public method name "JobPoster::security_clearance" is not in camel caps format
Loading history...
137 6
        return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class);
138
    }
139
140 12
    public function criteria() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function criteria()
Loading history...
141 12
        return $this->hasMany(\App\Models\Criteria::class);
142
    }
143
144
    public function job_applications() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_applications()
Loading history...
Coding Style introduced by
Public method name "JobPoster::job_applications" is not in camel caps format
Loading history...
145
        return $this->hasMany(\App\Models\JobApplication::class);
146
    }
147
148 12
    public function job_poster_key_tasks() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_poster_key_tasks()
Loading history...
Coding Style introduced by
Public method name "JobPoster::job_poster_key_tasks" is not in camel caps format
Loading history...
149 12
        return $this->hasMany(\App\Models\JobPosterKeyTask::class);
150
    }
151
152 12
    public function job_poster_questions() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_poster_questions()
Loading history...
Coding Style introduced by
Public method name "JobPoster::job_poster_questions" is not in camel caps format
Loading history...
153 12
        return $this->hasMany(\App\Models\JobPosterQuestion::class);
154
    }
155
156
    public function job_poster_translations() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function job_poster_translations()
Loading history...
Coding Style introduced by
Public method name "JobPoster::job_poster_translations" is not in camel caps format
Loading history...
157
        return $this->hasMany(\App\Models\JobPosterTranslation::class);
158
    }
159
160
    public function screening_plans()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function screening_plans()
Loading history...
Coding Style introduced by
Public method name "JobPoster::screening_plans" is not in camel caps format
Loading history...
161
    {
162
        return $this->hasMany(\App\Models\ScreeningPlan::class);
163
    }
164
165
    // Artificial Relations
166
167 16
    public function submitted_applications() {
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
Coding Style introduced by
Public method name "JobPoster::submitted_applications" is not in camel caps format
Loading history...
168
        return $this->hasMany(\App\Models\JobApplication::class)->whereHas('application_status', function ($query) {
0 ignored issues
show
Coding Style introduced by
The opening parenthesis of a multi-line function call should be the last content on the line.
Loading history...
169 16
            $query->where('name', '!=', 'draft');
170 16
        });
0 ignored issues
show
Coding Style introduced by
For multi-line function calls, the closing parenthesis should be on a new line.

If a function call spawns multiple lines, the coding standard suggests to move the closing parenthesis to a new line:

someFunctionCall(
    $firstArgument,
    $secondArgument,
    $thirdArgument
); // Closing parenthesis on a new line.
Loading history...
171
    }
172
173
    // Accessors
174
175
    // Methods
176
177 8
    public function isOpen() {
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
178 8
        return $this->published
179 8
            && $this->open_date_time->isPast()
180 8
            && $this->close_date_time->isFuture();
181
    }
182
183 4
    public function isClosed() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isClosed()
Loading history...
184 4
        return $this->published
185 4
            && $this->open_date_time->isPast()
186 4
            && $this->close_date_time->isPast();
187
    }
188
189 6
    public function timeRemaining() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function timeRemaining()
Loading history...
190 6
        $interval = $this->close_date_time->diff(Date::now());
191
192 6
        $d = $interval->d;
193 6
        $h = $interval->h;
194 6
        $m = $interval->i;
195 6
        $s = $interval->s;
196
197 6
        if ($d > 0) {
198 6
            $unit = 'day';
199 6
            $count = $d;
200 2
        } else if ($h > 0) {
201 2
            $unit = 'hour';
202 2
            $count = $h;
203
        } else if ($m > 0) {
204
            $unit = 'minute';
205
            $count = $m;
206
        } else {
207
            $unit = 'second';
208
            $count = $s;
209
        }
210
211 6
        $key = "common/time.$unit";
212
213 6
        return Lang::choice($key, $count);
214
    }
215
216 2
    public function status()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function status()
Loading history...
217
    {
218 2
        $status = 'draft';
219 2
        if ($this->isOpen()) {
220 2
            $status = 'posted';
221 2
        } else if ($this->isClosed()) {
222 2
            $status = 'closed';
223 2
        } else if ($this->review_requested_at !== null) {
224 2
            $status = 'submitted';
225
        } else {
226 2
            $status = 'draft';
227
        }
228
229 2
        return $status;
230
    }
231
}
232