Passed
Push — task/change-application-deadli... ( b4487f...923775 )
by Chris
09:42 queued 02:35
created

JobPoster::screening_plans()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 0
cts 0
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
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 int $department_id
26
 * @property int $province_id
27
 * @property int $salary_min
28
 * @property int $salary_max
29
 * @property int $noc
30
 * @property string $classification
31
 * @property int $security_clearance_id
32
 * @property int $language_requirement_id
33
 * @property boolean $remote_work_allowed
34
 * @property int $manager_id
35
 * @property boolean $published
36
 * @property \Jenssegers\Date\Date $created_at
37
 * @property \Jenssegers\Date\Date $updated_at
38
 *
39
 * @property int $submitted_applications_count
40
 *
41
 * @property \App\Models\Lookup\Department $department
42
 * @property \App\Models\Lookup\JobTerm $job_term
43
 * @property \App\Models\Lookup\LanguageRequirement $language_requirement
44
 * @property \App\Models\Manager $manager
45
 * @property \App\Models\Lookup\Province $province
46
 * @property \App\Models\Lookup\SecurityClearance $security_clearance
47
 * @property \Illuminate\Database\Eloquent\Collection $criteria
48
 * @property \Illuminate\Database\Eloquent\Collection $job_applications
49
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_key_tasks
50
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_questions
51
 * @property \Illuminate\Database\Eloquent\Collection $job_poster_translations
52
 * @property \Illuminate\Database\Eloquent\Collection $submitted_applications
53
 * @property \Illuminate\Database\Eloquent\Collection[ScreeningPlan] $screening_plans
54
 *
55
 * Localized Properties:
56
 * @property string $city
57
 * @property string $title
58
 * @property string $impact
59
 * @property string $branch
60
 * @property string $division
61
 * @property string $education
62
 *
63
 * Methods
64
 * @method boolean isOpen()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
65
 * @method string timeRemaining()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
66
 */
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...
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...
67
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...
68
69
    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...
70
    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...
71
72
    const TIMEZONE = 'America/Toronto';
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
    ];
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
    // @codeCoverageIgnoreStart
117
118
    public function department()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
119
    {
120
        return $this->belongsTo(\App\Models\Lookup\Department::class);
121
    }
122
123
    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...
124
    {
125
        return $this->belongsTo(\App\Models\Lookup\JobTerm::class);
126
    }
127
128
    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...
129
    {
130
        return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class);
131
    }
132
133
    public function manager()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function manager()
Loading history...
134
    {
135
        return $this->belongsTo(\App\Models\Manager::class);
136
    }
137
138
    public function province()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function province()
Loading history...
139
    {
140
        return $this->belongsTo(\App\Models\Lookup\Province::class);
141
    }
142
143
    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...
144
    {
145
        return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class);
146
    }
147
148
    public function criteria()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function criteria()
Loading history...
149
    {
150
        return $this->hasMany(\App\Models\Criteria::class);
151
    }
152
153
    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...
154
    {
155
        return $this->hasMany(\App\Models\JobApplication::class);
156
    }
157
158
    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...
159
    {
160
        return $this->hasMany(\App\Models\JobPosterKeyTask::class);
161
    }
162
163
    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...
164
    {
165
        return $this->hasMany(\App\Models\JobPosterQuestion::class);
166
    }
167
168
    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...
169
    {
170
        return $this->hasMany(\App\Models\JobPosterTranslation::class);
171
    }
172
173
    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...
174
    {
175
        return $this->hasMany(\App\Models\ScreeningPlan::class);
176
    }
177
178
    // Artificial Relations
179
180
    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...
181
    {
182
        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...
183
            $query->where('name', '!=', 'draft');
184
        });
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...
185
    }
186
187
    // @codeCoverageIgnoreEnd
188
189
    // Accessors
190
191
    // Methods
192
193
    /**
194
     * Formatted and localized date and time the Job Poster closes.
195
     *
196
     * @return string
197
     */
198 2
    public function applyBy() : string
199
    {
200 2
        $date = new Date($this->close_date_time, self::TIMEZONE);
201 2
        return $date->format('F jS, Y, gA T');
202
    }
203
204
    /**
205
     * Check if a Job Poster is open for applications.
206
     *
207
     * @return boolean
208
     */
209 2
    public function isOpen() : bool
210
    {
211 2
        return $this->published
212 2
            && $this->open_date_time->isPast()
213 2
            && $this->close_date_time->isFuture();
214
    }
215
216
    /**
217
     * Calculate the remaining time a Job Poster is open.
218
     *
219
     * @return string
220
     */
221 2
    public function timeRemaining() : string
222
    {
223 2
        $interval = $this->close_date_time->diff(Date::now());
224
225 2
        $d = $interval->d;
226 2
        $h = $interval->h;
227 2
        $m = $interval->i;
228 2
        $s = $interval->s;
229
230 2
        if ($d > 0) {
231 2
            $unit = 'day';
232 2
            $count = $d;
233 2
        } else if ($h > 0) {
234 2
            $unit = 'hour';
235 2
            $count = $h;
236 2
        } else if ($m > 0) {
237 2
            $unit = 'minute';
238 2
            $count = $m;
239
        } else {
240 2
            $unit = 'second';
241 2
            $count = $s;
242
        }
243
244 2
        $key = "common/time.$unit";
245
246 2
        return Lang::choice($key, $count);
247
    }
248
}
249