Passed
Push — task/change-application-deadli... ( 5f73bf...0e885f )
by
unknown
09:24
created

JobPoster::province()   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
rs 10
c 0
b 0
f 0
ccs 0
cts 0
cp 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
 *
54
 * Localized Properties:
55
 * @property string $city
56
 * @property string $title
57
 * @property string $impact
58
 * @property string $branch
59
 * @property string $division
60
 * @property string $education
61
 *
62
 * Methods
63
 * @method boolean isOpen()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
64
 * @method string timeRemaining()
0 ignored issues
show
Coding Style introduced by
Tag value indented incorrectly; expected 3 spaces but found 1
Loading history...
65
 */
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...
66
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...
67
68
    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...
69
    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...
70
71
    const TIMEZONE = 'America/Toronto';
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
    ];
92
    protected $fillable = [
93
        'job_term_id',
94
        'term_qty',
95
        'open_date_time',
96
        'close_date_time',
97
        'start_date_time',
98
        'department_id',
99
        'province_id',
100
        'salary_min',
101
        'salary_max',
102
        'noc',
103
        'classification',
104
        'security_clearance_id',
105
        'language_requirement_id',
106
        'remote_work_allowed',
107
        'published'
108
    ];
109
    protected $withCount = ['submitted_applications'];
110
111
    protected $dispatchesEvents = [
112
        'saved' => JobSaved::class,
113
    ];
114
115
    // @codeCoverageIgnoreStart
116
117
    public function department()
0 ignored issues
show
Coding Style introduced by
You must use "/**" style comments for a function comment
Loading history...
118
    {
119
        return $this->belongsTo(\App\Models\Lookup\Department::class);
120
    }
121
122
    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
    {
124
        return $this->belongsTo(\App\Models\Lookup\JobTerm::class);
125
    }
126
127
    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...
128
    {
129
        return $this->belongsTo(\App\Models\Lookup\LanguageRequirement::class);
130
    }
131
132
    public function manager()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function manager()
Loading history...
133
    {
134
        return $this->belongsTo(\App\Models\Manager::class);
135
    }
136
137
    public function province()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function province()
Loading history...
138
    {
139
        return $this->belongsTo(\App\Models\Lookup\Province::class);
140
    }
141
142
    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...
143
    {
144
        return $this->belongsTo(\App\Models\Lookup\SecurityClearance::class);
145
    }
146
147
    public function criteria()
0 ignored issues
show
Coding Style introduced by
Missing doc comment for function criteria()
Loading history...
148
    {
149
        return $this->hasMany(\App\Models\Criteria::class);
150
    }
151
152
    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...
153
    {
154
        return $this->hasMany(\App\Models\JobApplication::class);
155
    }
156
157
    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...
158
    {
159
        return $this->hasMany(\App\Models\JobPosterKeyTask::class);
160
    }
161
162
    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...
163
    {
164
        return $this->hasMany(\App\Models\JobPosterQuestion::class);
165
    }
166
167
    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...
168
    {
169
        return $this->hasMany(\App\Models\JobPosterTranslation::class);
170
    }
171
172
    // Artificial Relations
173
174
    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...
175
    {
176
        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...
177
            $query->where('name', '!=', 'draft');
178
        });
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...
179
    }
180
181
    // @codeCoverageIgnoreEnd
182
183
    // Accessors
184
185
    // Methods
186
187
    /**
188
     * Formatted and localized date and time the Job Poster closes.
189
     *
190
     * @return string
191
     */
192 2
    public function applyBy() : string
193
    {
194 2
        $date = new Date($this->close_date_time, self::TIMEZONE);
195 2
        return $date->format('F jS, Y, gA T');
196
    }
197
198
    /**
199
     * Check if a Job Poster is open for applications.
200
     *
201
     * @return boolean
202
     */
203 2
    public function isOpen() : bool
204
    {
205 2
        return $this->published
206 2
            && $this->open_date_time->isPast()
207 2
            && $this->close_date_time->isFuture();
208
    }
209
210
    /**
211
     * Calculate the remaining time a Job Poster is open.
212
     *
213
     * @return string
214
     */
215 2
    public function timeRemaining() : string
216
    {
217 2
        $interval = $this->close_date_time->diff(Date::now());
218
219 2
        $d = $interval->d;
220 2
        $h = $interval->h;
221 2
        $m = $interval->i;
222 2
        $s = $interval->s;
223
224 2
        if ($d > 0) {
225 2
            $unit = 'day';
226 2
            $count = $d;
227 2
        } else if ($h > 0) {
228 2
            $unit = 'hour';
229 2
            $count = $h;
230 2
        } else if ($m > 0) {
231 2
            $unit = 'minute';
232 2
            $count = $m;
233
        } else {
234 2
            $unit = 'second';
235 2
            $count = $s;
236
        }
237
238 2
        $key = "common/time.$unit";
239
240 2
        return Lang::choice($key, $count);
241
    }
242
}
243