Passed
Push — task/add_null_states ( 93767f...291766 )
by
unknown
10:33 queued 11s
created

Skill   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 22.22%

Importance

Changes 0
Metric Value
wmc 3
eloc 18
dl 0
loc 49
ccs 2
cts 9
cp 0.2222
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A skill_declarations() 0 3 1
A toArray() 0 6 1
A skill_type() 0 3 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\CrudTrait;
11
use \Backpack\CRUD\ModelTraits\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
 *
21
 * @property \App\Models\Lookup\SkillType $skill_type
22
 * @property \Illuminate\Database\Eloquent\Collection $skill_declarations
23
 */
24
class Skill extends BaseModel
25
{
26
    use CrudTrait;
0 ignored issues
show
introduced by
The trait Backpack\CRUD\CrudTrait requires some properties which are not provided by App\Models\Skill: $Type, $fakeColumns
Loading history...
27
    use HasTranslations;
28
29
    /**
30
     * @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...
31
     * */
32
    protected $casts = [
33
        'skill_type_id' => 'int'
34
    ];
35
    /**
36
     * @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...
37
     * */
38
    protected $fillable = [
39
        'name',
40
        'description',
41
        'skill_type_id'
42
    ];
43
    /**
44
     * @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...
45
     * */
46
    public $translatable = [
47
        'name',
48
        'description',
49
    ];
50
51 2
    public function skill_type() // phpcs:ignore
52
    {
53 2
        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
    /**
62
     * Override the toArray() method to return the localized properties for
63
     * name and description. This was causing issues for ajax responses.
64
     *
65
     * @return mixed[]
66
     */
67
    public function toArray() : array
68
    {
69
        $array = parent::toArray();
70
        $array['name'] = $this->name;
71
        $array['description'] = $this->description;
72
        return $array;
73
    }
74
}
75