Passed
Push — bugfix/skills-not-displaying-p... ( cc8641 )
by Chris
08:41
created

Skill::toArray()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
/**
4
 * Created by Reliese Model.
5
 * Date: Thu, 12 Jul 2018 22:39:27 +0000.
6
 */
0 ignored issues
show
Coding Style introduced by
PHP version not specified
Loading history...
Coding Style introduced by
Missing @category tag in file comment
Loading history...
Coding Style introduced by
Missing @package tag in file comment
Loading history...
Coding Style introduced by
Missing @author tag in file comment
Loading history...
Coding Style introduced by
Missing @license tag in file comment
Loading history...
Coding Style introduced by
Missing @link tag in file comment
Loading history...
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
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
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
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
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
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
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
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
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 4
    public function skill_type() // phpcs:ignore
52
    {
53 4
        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