Passed
Push — feature/manager_poster_index ( 088fdc...087dce )
by Chris
07:33
created

JobPoster::setPublishedAttribute()   A

Complexity

Conditions 5
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 5

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 9.6111
c 0
b 0
f 0
ccs 6
cts 6
cp 1
cc 5
nc 3
nop 1
crap 5
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 \Jessengers\Date\Date $published_at
27
 * @property int $department_id
28
 * @property int $province_id
29
 * @property int $salary_min
30
 * @property int $salary_max
31
 * @property int $noc
32
 * @property string $classification
33
 * @property int $security_clearance_id
34
 * @property int $language_requirement_id
35
 * @property boolean $remote_work_allowed
36
 * @property int $manager_id
37
 * @property boolean $published
38
 * @property \Jenssegers\Date\Date $created_at
39
 * @property \Jenssegers\Date\Date $updated_at
40
 *
41
 * @property int $submitted_applications_count
42
 *
43
 * @property \App\Models\Lookup\Department $department
44
 * @property \App\Models\Lookup\JobTerm $job_term
45
 * @property \App\Models\Lookup\LanguageRequirement $language_requirement
46
 * @property \App\Models\Manager $manager
47
 * @property \App\Models\Lookup\Province $province
48
 * @property \App\Models\Lookup\SecurityClearance $security_clearance
49
 * @property \Illuminate\Database\Eloquent\Collection $criteria
50
 * @property \Illuminate\Database\Eloquent\Collection $job_applications
51
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_key_tasks
52
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_questions
53
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_translations
54
 * @property \Illuminate\Database\Eloquent\Collection $submitted_applications
55
 * @property \Illuminate\Database\Eloquent\Collection[ScreeningPlan] $screening_plans
56
 *
57
 * Localized Properties:
58
 * @property string $city
59
 * @property string $title
60
 * @property string $impact
61
 * @property string $branch
62
 * @property string $division
63
 * @property string $education
64
 *
65
 * Methods
66
 * @method boolean isOpen()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
67
 * @method string timeRemaining()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
68
 */
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...
69
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...
70
71
    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...
72
    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...
73
74
    public $translatedAttributes = ['city', 'title', 'impact', 'branch', 'division', 'education'];
75
    protected $casts = [
76
        'job_term_id' => 'int',
77
        'department_id' => 'int',
78
        'province_id' => 'int',
79
        'salary_min' => 'int',
80
        'salary_max' => 'int',
81
        'noc' => 'int',
82
        'security_clearance_id' => 'int',
83
        'language_requirement_id' => 'int',
84
        'remote_work_allowed' => 'boolean',
85
        'manager_id' => 'int',
86
        'published' => 'boolean'
87
    ];
88
    protected $dates = [
89
        'open_date_time',
90
        'close_date_time',
91
        'start_date_time',
92
        'review_requested_at',
93
        'published_at'
94
    ];
95
    protected $fillable = [
96
        'job_term_id',
97
        'term_qty',
98
        'open_date_time',
99
        'close_date_time',
100
        'start_date_time',
101
        'department_id',
102
        'province_id',
103
        'salary_min',
104
        'salary_max',
105
        'noc',
106
        'classification',
107
        'security_clearance_id',
108
        'language_requirement_id',
109
        'remote_work_allowed',
110
        'published'
111
    ];
112
    protected $withCount = ['submitted_applications'];
113
114
    protected $dispatchesEvents = [
115
        'saved' => JobSaved::class,
116
    ];
117
118 6
    public function department() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function department()
Loading history...
119 6
        return $this->belongsTo(\App\Models\Lookup\Department::class);
120
    }
121
122 6
    public function job_term() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::job_term" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function job_term()
Loading history...
123 6
        return $this->belongsTo(\App\Models\Lookup\JobTerm::class);
124
    }
125
126 6
    public function language_requirement() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::language_requirement" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function language_requirement()
Loading history...
127 6
        return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class);
128
    }
129
130 20
    public function manager() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function manager()
Loading history...
131 20
        return $this->belongsTo(\App\Models\Manager::class);
132
    }
133
134 6
    public function province() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function province()
Loading history...
135 6
        return $this->belongsTo(\App\Models\Lookup\Province::class);
136
    }
137
138 6
    public function security_clearance() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::security_clearance" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function security_clearance()
Loading history...
139 6
        return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class);
140
    }
141
142 14
    public function criteria() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function criteria()
Loading history...
143 14
        return $this->hasMany(\App\Models\Criteria::class);
144
    }
145
146
    public function job_applications() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::job_applications" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function job_applications()
Loading history...
147
        return $this->hasMany(\App\Models\JobApplication::class);
148
    }
149
150 14
    public function job_poster_key_tasks() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::job_poster_key_tasks" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function job_poster_key_tasks()
Loading history...
151 14
        return $this->hasMany(\App\Models\JobPosterKeyTask::class);
152
    }
153
154 14
    public function job_poster_questions() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::job_poster_questions" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function job_poster_questions()
Loading history...
155 14
        return $this->hasMany(\App\Models\JobPosterQuestion::class);
156
    }
157
158
    public function job_poster_translations() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::job_poster_translations" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function job_poster_translations()
Loading history...
159
        return $this->hasMany(\App\Models\JobPosterTranslation::class);
160
    }
161
162
    public function screening_plans()
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::screening_plans" is not in camel caps format
Loading history...
Coding Style introduced by
Missing doc comment for function screening_plans()
Loading history...
163
    {
164
        return $this->hasMany(\App\Models\ScreeningPlan::class);
165
    }
166
167
    // Artificial Relations
168
169 20
    public function submitted_applications() {
0 ignored issues
show
Coding Style introduced by
Public method name "JobPoster::submitted_applications" is not in camel caps format
Loading history...
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
170
        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...
171 20
            $query->where('name', '!=', 'draft');
172 20
        });
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...
173
    }
174
175
    // Accessors
176
177
    // Mutators
178 32
    public function setPublishedAttribute($value)
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
179
    {
180 32
        if ($value && $this->open_date_time->isPast()) {
181 28
            $this->attributes['published_at'] = new Date();
182 26
        } elseif ($value && $this->open_date_time->isFuture()) {
183 2
            $this->attributes['published_at'] = $this->open_date_time;
184
        }
185 32
        $this->attributes['published'] = $value;
186 32
    }
187
188
    // Methods
189
190 8
    public function isOpen() {
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
191 8
        return $this->published
192 8
            && $this->open_date_time->isPast()
193 8
            && $this->close_date_time->isFuture();
194
    }
195
196 4
    public function isClosed() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function isClosed()
Loading history...
197 4
        return $this->published
198 4
            && $this->open_date_time->isPast()
199 4
            && $this->close_date_time->isPast();
200
    }
201
202 6
    public function timeRemaining() {
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function timeRemaining()
Loading history...
203 6
        $interval = $this->close_date_time->diff(Date::now());
204
205 6
        $d = $interval->d;
206 6
        $h = $interval->h;
207 6
        $m = $interval->i;
208 6
        $s = $interval->s;
209
210 6
        if ($d > 0) {
211 6
            $unit = 'day';
212 6
            $count = $d;
213 2
        } else if ($h > 0) {
214 2
            $unit = 'hour';
215 2
            $count = $h;
216
        } else if ($m > 0) {
217
            $unit = 'minute';
218
            $count = $m;
219
        } else {
220
            $unit = 'second';
221
            $count = $s;
222
        }
223
224 6
        $key = "common/time.$unit";
225
226 6
        return Lang::choice($key, $count);
227
    }
228
229 2
    public function status()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function status()
Loading history...
230
    {
231 2
        $status = 'draft';
232 2
        if ($this->isOpen()) {
233 2
            $status = 'posted';
234 2
        } else if ($this->isClosed()) {
235 2
            $status = 'closed';
236 2
        } else if ($this->review_requested_at !== null) {
237 2
            $status = 'submitted';
238
        } else {
239 2
            $status = 'draft';
240
        }
241
242 2
        return $status;
243
    }
244
}
245