Completed
Push — master ( 6f477a...704639 )
by Francesco
04:05
created

Question   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 41
rs 10
c 0
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A getOptionsAttribute() 0 3 1
1
<?php
2
declare(strict_types = 1);
3
4
namespace App\Models;
5
6
use App\Models\Traits\EloquentGetTableName;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Relations\BelongsTo;
9
use Illuminate\Database\Eloquent\Relations\HasMany;
10
use Illuminate\Database\Eloquent\SoftDeletes;
11
12
class Question extends Model
13
{
14
15
    use SoftDeletes;
16
    use EloquentGetTableName;
17
18
    /**
19
     * The attributes that should be mutated to dates.
20
     *
21
     * @var array
22
     */
23
    protected $dates = ['deleted_at'];
24
    
25
    /**
26
     * The attributes that should be cast to native types.
27
     *
28
     * @var array
29
     */
30
    protected $casts = ['required' => 'boolean'];
31
32
    /**
33
     * Get the possible answers of this question
34
     * @return HasMany
35
     */
36
    public function answers() : HasMany
37
    {
38
        return $this->hasMany('App\Models\Answer');
39
    }
40
41
    /**
42
     * Get the section of this question
43
     * @return BelongsTo
44
     */
45
    public function section() : BelongsTo
46
    {
47
        return $this->belongsTo('App\Models\Section');
48
    }
49
    
50
    public function getOptionsAttribute()
51
    {
52
        return json_decode($this->attributes['options'] ?? '');
53
    }
54
55
}
56