Passed
Push — feature/experience-api ( 04f855...94b2f2 )
by Tristan
06:04
created

ExperienceAward   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 26
dl 0
loc 66
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A award_recipient_type() 0 3 1
A experienceable() 0 3 1
A experienceTypeName() 0 3 1
A boot() 0 8 2
A award_recognition_type() 0 3 1
A experience_skills() 0 3 1
A skills() 0 3 1
1
<?php
2
3
namespace App\Models;
4
5
use App\Models\BaseModel;
6
7
/**
8
 * Class ExperienceAward
9
 *
10
 * @property int $id
11
 * @property string $title
12
 * @property int $award_recipient_type_id
13
 * @property string $issued_by
14
 * @property int $award_recognition_type_id
15
 * @property \Jenssegers\Date\Date $awarded_date
16
 * @property int $experienceable_id
17
 * @property string $experienceable_type
18
 * @property boolean $is_education_requirement
19
 * @property \Jenssegers\Date\Date $created_at
20
 * @property \Jenssegers\Date\Date $updated_at
21
 *
22
 * @property \App\Models\Applicant|\App\Models\JobApplication $experienceable
23
 * @property \Illuminate\Database\Eloquent\Collection $skills
24
 * @property \Illuminate\Database\Eloquent\Collection $experience_skills
25
 *
26
 * @method string experienceTypeName
27
 */
28
class ExperienceAward extends BaseModel
29
{
30
    protected $casts = [
31
        'title' => 'string',
32
        'award_recipient_type_id' => 'int',
33
        'issued_by' => 'string',
34
        'award_recognition_type_id' => 'int',
35
        'awarded_date' => 'date',
36
        'is_education_requirement' => 'boolean'
37
    ];
38
39
    protected $fillable = [
40
        'title',
41
        'award_recipient_type_id',
42
        'issued_by',
43
        'award_recognition_type_id',
44
        'awarded_date',
45
        'is_education_requirement'
46
    ];
47
48
    protected $table = 'experiences_award';
49
50
    public static function boot()
51
    {
52
        parent::boot();
53
54
        // Delete associated ExperienceSkills when this is deleted.
55
        static::deleting(function ($award): void {
56
            foreach ($award->experience_skills as $es) {
57
                $es->delete();
58
            }
59
        });
60
    }
61
62
    public function award_recipient_type() //phpcs:ignore
63
    {
64
        return $this->belongsTo(\App\Models\Lookup\AwardRecipientType::class);
65
    }
66
67
    public function award_recognition_type() //phpcs:ignore
68
    {
69
        return $this->belongsTo(\App\Models\Lookup\AwardRecognitionType::class);
70
    }
71
72
    public function experienceable() //phpcs:ignore
73
    {
74
        return $this->morphTo();
75
    }
76
77
    public function skills()
78
    {
79
        return $this->morphToMany(\App\Models\Skill::class, 'experience', 'experience_skills');
80
    }
81
82
    public function experience_skills() //phpcs:ignore
83
    {
84
        return $this->morphMany(\App\Models\ExperienceSkill::class, 'experience');
85
    }
86
87
    /**
88
     * Returns the name of this experience type. Used to distinguish from other Experience models.
89
     * @return string Returns the string 'award'.
90
     */
91
    public function experienceTypeName(): string
92
    {
93
        return 'award';
94
    }
95
}
96