Passed
Push — task/skill-skillcategory-relat... ( 4be7cf )
by
unknown
06:50
created

Skill::skill_categories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace App\Models;
4
5
use Backpack\CRUD\app\Models\Traits\CrudTrait;
6
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
7
8
/**
9
 * Class Skill
10
 *
11
 * @property int $id
12
 * @property string $name
13
 * @property string $description
14
 * @property int $skill_type_id
15
 * @property boolean $is_culture_skill
16
 * @property boolean $is_future_skill
17
 * @property \Jenssegers\Date\Date $created_at
18
 * @property \Jenssegers\Date\Date $updated_at
19
 *
20
 * @property \App\Models\Lookup\SkillType $skill_type
21
 * @property \Illuminate\Database\Eloquent\Collection $skill_declarations
22
 * @property \Illuminate\Database\Eloquent\Collection $classifications
23
 * @property \App\Models\ExperienceAward|\App\Models\ExperienceCommunity|\App\Models\ExperienceEducation|\App\Models\ExperiencePersonal|\App\Models\ExperienceWork $experience
24
 * @property \Illuminate\Database\Eloquent\Collection $experience_skills
25
 */
26
class Skill extends BaseModel
27
{
28
    use CrudTrait;
29
    use HasTranslations;
30
31
    protected $casts = [
32
        'skill_type_id' => 'int',
33
        'is_culture_skill' => 'boolean',
34
        'is_future_skill' => 'boolean',
35
    ];
36
37
    protected $fillable = [
38
        'name',
39
        'description',
40
        'skill_type_id',
41
        'is_culture_skill',
42
        'is_future_skill',
43
        'classifications'
44
    ];
45
46
    public $translatable = [
47
        'name',
48
        'description',
49
    ];
50
51
    public function skill_type() // phpcs:ignore
52
    {
53
        return $this->belongsTo(\App\Models\Lookup\SkillType::class);
54
    }
55
56
    public function skill_declarations() // phpcs:ignore
57
    {
58
        return $this->hasMany(\App\Models\SkillDeclaration::class);
59
    }
60
61
    public function classifications() // phpcs:ignore
62
    {
63
        return $this->belongsToMany(\App\Models\Classification::class)->withTimestamps();
64
    }
65
66
    // Version 2 application models.
67
68
    public function experiences_work() // phpcs:ignore
69
    {
70
        return $this->morphedByMany(\App\Models\ExperienceWork::class, 'experience', 'experience_skills');
71
    }
72
73
    public function experiences_personal() // phpcs:ignore
74
    {
75
        return $this->morphedByMany(\App\Models\ExperiencePersonal::class, 'experience', 'experience_skills');
76
    }
77
78
    public function experiences_education() // phpcs:ignore
79
    {
80
        return $this->morphedByMany(\App\Models\ExperienceEducation::class, 'experience', 'experience_skills');
81
    }
82
83
    public function experiences_award() // phpcs:ignore
84
    {
85
        return $this->morphedByMany(\App\Models\ExperienceAward::class, 'experience', 'experience_skills');
86
    }
87
88
    public function experiences_community() // phpcs:ignore
89
    {
90
        return $this->morphedByMany(\App\Models\ExperienceCommunity::class, 'experience', 'experience_skills');
91
    }
92
93
    public function experience_skills() // phpcs:ignore
94
    {
95
        return $this->hasMany(\App\Models\ExperienceSkill::class);
96
    }
97
98
    public function skill_categories() // phpcs:ignore
99
    {
100
        return $this->belongsToMany(\App\Models\SkillCategory::class, 'skill_categories_skills');
101
    }
102
103
    /**
104
     * Check for a null "is_culture_skill" and pass false instead.
105
     *
106
     * @param mixed $value Incoming value for the "is_culture_skill" attribute.
107
     *
108
     * @return void
109
     */
110
    public function setIsCultureSkillAttribute($value): void
111
    {
112
        if ($value === null) {
113
            $value = false;
114
        }
115
        $this->attributes['is_culture_skill'] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
116
    }
117
118
    /**
119
     * Check for a null "is_future_skill" and pass false instead.
120
     *
121
     * @param mixed $value Incoming value for the "is_future_skill" attribute.
122
     *
123
     * @return void
124
     */
125
    public function setIsFutureSkillAttribute($value): void
126
    {
127
        if ($value === null) {
128
            $value = false;
129
        }
130
        $this->attributes['is_future_skill'] = $value;
0 ignored issues
show
Bug Best Practice introduced by
The property attributes does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
131
    }
132
}
133