Passed
Pull Request — release/1.0.15 (#1655)
by Tristan
10:06 queued 02:47
created

Skill::setIsCultureSkillAttribute()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
7
8
namespace App\Models;
9
10
use Backpack\CRUD\app\Models\Traits\CrudTrait;
11
use Backpack\CRUD\app\Models\Traits\SpatieTranslatable\HasTranslations;
12
13
/**
14
 * Class Skill
15
 *
16
 * @property int $id
17
 * @property string $name
18
 * @property string $description
19
 * @property int $skill_type_id
20
 * @property boolean $is_culture_skill
21
 * @property boolean $is_future_skill
22
 * @property \Jenssegers\Date\Date $created_at
23
 * @property \Jenssegers\Date\Date $updated_at
24
 *
25
 * @property \App\Models\Lookup\SkillType $skill_type
26
 * @property \Illuminate\Database\Eloquent\Collection $skill_declarations
27
 * @property \Illuminate\Database\Eloquent\Collection $classifications
28
 */
29
class Skill extends BaseModel
30
{
31
    use CrudTrait;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\app\Models\Traits\CrudTrait requires some properties which are not provided by App\Models\Skill: $Type, $fakeColumns
Loading history...
32
    use HasTranslations;
33
34
    /**
35
     * @var $casts string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $casts at position 0 could not be parsed: Unknown type name '$casts' at position 0 in $casts.
Loading history...
36
     * */
37
    protected $casts = [
38
        'skill_type_id' => 'int',
39
        'is_culture_skill' => 'boolean',
40
        'is_future_skill' => 'boolean',
41
    ];
42
    /**
43
     * @var $fillable string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $fillable at position 0 could not be parsed: Unknown type name '$fillable' at position 0 in $fillable.
Loading history...
44
     * */
45
    protected $fillable = [
46
        'name',
47
        'description',
48
        'skill_type_id',
49
        'is_culture_skill',
50
        'is_future_skill',
51
        'classifications'
52
    ];
53
    /**
54
     * @var $translatable string[]
0 ignored issues
show
Documentation Bug introduced by
The doc comment $translatable at position 0 could not be parsed: Unknown type name '$translatable' at position 0 in $translatable.
Loading history...
55
     * */
56
    public $translatable = [
57
        'name',
58
        'description',
59
    ];
60
61
    public function skill_type() // phpcs:ignore
62
    {
63
        return $this->belongsTo(\App\Models\Lookup\SkillType::class);
64
    }
65
66
    public function skill_declarations() // phpcs:ignore
67
    {
68
        return $this->hasMany(\App\Models\SkillDeclaration::class);
69
    }
70
71
    public function classifications() // phpcs:ignore
72
    {
73
        return $this->belongsToMany(\App\Models\Classification::class)->withTimestamps();
74
    }
75
76
    /**
77
     * Check for a null "is_culture_skill" and pass false instead.
78
     *
79
     * @param mixed $value Incoming value for the "is_culture_skill" attribute.
80
     *
81
     * @return void
82
     */
83
    public function setIsCultureSkillAttribute($value) : void
84
    {
85
        if ($value === null) {
86
            $value = false;
87
        }
88
        $this->attributes['is_culture_skill'] = $value;
89
    }
90
91
    /**
92
     * Check for a null "is_future_skill" and pass false instead.
93
     *
94
     * @param mixed $value Incoming value for the "is_future_skill" attribute.
95
     *
96
     * @return void
97
     */
98
    public function setIsFutureSkillAttribute($value) : void
99
    {
100
        if ($value === null) {
101
            $value = false;
102
        }
103
        $this->attributes['is_future_skill'] = $value;
104
    }
105
106
    /**
107
     * Override the toArray() method to return the localized properties for
108
     * name and description. This was causing issues for ajax responses.
109
     *
110
     * @return mixed[]
111
     */
112
    public function toArray() : array
113
    {
114
        $array = parent::toArray();
115
        $array['name'] = $this->name;
116
        $array['description'] = $this->description;
117
        return $array;
118
    }
119
}
120