Passed
Push — dependabot/npm_and_yarn/dev/st... ( 917c39...79f3f4 )
by
unknown
12:32 queued 07:14
created

HrAdvisor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 16
c 1
b 0
f 0
dl 0
loc 70
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A user() 0 3 1
A getClaimedJobIdsAttribute() 0 3 1
A department() 0 3 1
A claimed_jobs() 0 5 1
A getNameAttribute() 0 6 2
1
<?php
2
3
namespace App\Models;
4
5
/**
6
 * Class HrAdvisor
7
 *
8
 * @property int $id
9
 * @property int $user_id
10
 * @property int $department_id
11
 *
12
 * @property \App\Models\User $user
13
 * @property \App\Models\Lookup\Department $department
14
 * @property \Illuminate\Database\Eloquent\Collection $job_posters
15
 * @property \Jenssegers\Date\Date $created_at
16
 * @property \Jenssegers\Date\Date $updated_at
17
 *
18
 * Computed Properties
19
 * @property string $name
20
 * @property int[] $claimed_job_ids
21
 */
22
class HrAdvisor extends BaseModel
23
{
24
    /**
25
     * @var string[] $casts
26
     */
27
    protected $casts = [
28
        'department_id' => 'int',
29
        'user_id' => 'int'
30
    ];
31
32
    /**
33
     * The attributes that should be visible in arrays.
34
     *
35
     * @var array
36
     */
37
    protected $visible = ['id', 'department_id', 'user_id', 'name', 'claimed_job_ids'];
38
39
    /**
40
     * @var string[] $fillable
41
     */
42
    protected $fillable = ['department_id'];
43
44
45
46
    /**
47
     * The accessors to append to the model's array form.
48
     *
49
     * @var array
50
     */
51
    protected $appends = ['name', 'claimed_job_ids'];
52
53
    public function user()
54
    {
55
        return $this->belongsTo(\App\Models\User::class);
56
    }
57
58
    public function department()
59
    {
60
        return $this->belongsTo(\App\Models\Lookup\Department::class);
61
    }
62
63
    public function claimed_jobs()
64
    {
65
        return $this->belongsToMany(
66
            \App\Models\JobPoster::class,
67
            'claimed_jobs'
68
        );
69
    }
70
71
    /**
72
     * Return the full name of the User associated with this HR Advisor.
73
     *
74
     * @return string
75
     */
76
    public function getNameAttribute(): string
77
    {
78
        if ($this->user !== null) {
79
            return $this->user->first_name . ' ' . $this->user->last_name;
80
        }
81
        return '';
82
    }
83
84
    /**
85
     * Return an array of ids of claimed jobs.
86
     *
87
     * @return array
88
     */
89
    public function getClaimedJobIdsAttribute()
90
    {
91
        return $this->claimed_jobs()->allRelatedIds();
92
    }
93
}
94