Completed
Push — master ( 398d0f...310d56 )
by Pascal
11:17 queued 06:22
created

ScoreModel::Attribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Pbmedia\Specifications\Laravel\Models;
4
5
use Illuminate\Database\Eloquent\Model;
6
use Illuminate\Database\Eloquent\Relations\BelongsTo;
7
use Illuminate\Database\Eloquent\Relations\MorphTo;
8
use Pbmedia\Specifications\AttributeScore;
9
use Pbmedia\Specifications\Interfaces\Score;
10
11
class ScoreModel extends Model implements Score
12
{
13
    /**
14
     * {@inheritDoc}
15
     */
16
    protected $fillable = ['attribute_id', 'value'];
17
18
    /**
19
     * {@inheritDoc}
20
     */
21
    protected $table = 'specifications_scores';
22
23
    /**
24
     * {@inheritDoc}
25
     */
26
    protected $casts = [
27
        'value' => 'json',
28
    ];
29
30
    /**
31
     * Helper method to quickly instantiate a new ScoreModel.
32
     *
33
     * @return \Pbmedia\Specifications\Laravel\Models\ScoreModel
34
     */
35
    public static function withValue($value): ScoreModel
36
    {
37
        return new static(compact('value'));
38
    }
39
40
    /**
41
     * Returns the value attribute.
42
     *
43
     * @return mixed
44
     */
45
    public function getValue()
46
    {
47
        return $this->value;
48
    }
49
50
    /**
51
     * Returns the value attribute.
52
     *
53
     * @return mixed
54
     */
55
    public function getAttributeScore(): AttributeScore
56
    {
57
        return new AttributeScore($this->Attribute, $this);
58
    }
59
60
    /**
61
     * Defines the relationship with the AttributeModel.
62
     *
63
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
64
     */
65
    public function Attribute(): BelongsTo
66
    {
67
        return $this->belongsTo(AttributeModel::class);
68
    }
69
70
    /**
71
     * Defines the relationship with the model that will be specified.
72
     *
73
     * @return \Illuminate\Database\Eloquent\Relations\MorphTo
74
     */
75
    public function Specifiable(): MorphTo
76
    {
77
        return $this->morphTo();
78
    }
79
}
80