Passed
Push — master ( 9c76a8...94f343 )
by Bertrand
34:04 queued 24:59
created

CharacteristicsModel::picturePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
4
namespace App\Src\UseCases\Infra\Sql\Model;
5
6
7
use App\Src\UseCases\Domain\Context\Dto\CharacteristicDto;
8
use App\Src\UseCases\Domain\Context\Model\Characteristic;
9
use App\User;
10
use Database\Factories\CharacteristicFactory;
11
use Illuminate\Database\Eloquent\Factories\HasFactory;
12
use Illuminate\Database\Eloquent\Model;
13
14
class CharacteristicsModel extends Model
15
{
16
    use HasFactory;
17
18
    protected $table = 'characteristics';
19
20
    protected $fillable = [
21
        'uuid',
22
        'main',
23
        'priority',
24
        'icon',
25
        'page_label',
26
        'pretty_page_label',
27
        'page_id',
28
        'type',
29
        'code',
30
        'visible',
31
    ];
32
33
    protected $casts = [
34
        'opt' => 'array'
35
    ];
36
37
    public function users()
38
    {
39
        return $this->belongsToMany(User::class)
40
            ->using(UserCharacteristicsModel::class);
41
    }
42
43
    public function toDto()
44
    {
45
        $icon = null;
46
        if(isset($this->icon)){
47
            $icon = route('api.icon.serve', ['id' => $this->uuid]);
48
        }
49
        return new CharacteristicDto(
50
            $this->uuid,
51
            $this->page_label,
52
            $this->type,
53
            $icon,
54
            $this->pretty_page_label,
55
            $this->opt ?? []
56
        );
57
    }
58
59
    public function picturePath():string
60
    {
61
        return storage_path('app/public/characteristics/' . $this->uuid . '.png');
62
    }
63
64
    public function toDomain()
65
    {
66
        return new Characteristic($this->uuid, $this->type, $this->code, $this->attributes['visible']);
67
    }
68
69
    protected static function newFactory()
70
    {
71
        return CharacteristicFactory::new();
72
    }
73
}
74