Test Failed
Push — master ( 65fd5f...3b2076 )
by Mike
03:58
created

Message::getIdAttribute()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace GeneaLabs\LaravelMessenger;
6
7
use Illuminate\Support\Str;
8
use Jenssegers\Model\Model;
9
10
class Message extends Model
11
{
12
    protected $appends = [
13
        "id",
14
        'autoHide',
15
        'framework',
16
        'message',
17
        'level',
18
        'title',
19
        'type',
20
    ];
21
    protected $casts = [
22
        'autoHide' => 'boolean',
23
    ];
24
    protected $fillable = [
25
        "id",
26
        'autoHide',
27
        'framework',
28
        'message',
29
        'level',
30
        'title',
31
        'type',
32
    ];
33
34
    public function getIdAttribute(): string
35
    {
36
         $this->attributes["id"] = $this->attributes["id"]
37
             ?? Str::random(16);
38
39
        return $this->attributes["id"];
40
    }
41
42
    public function getAutoHideAttribute(): bool
43
    {
44
        return ($this->attributes['autoHide'] === true);
45
    }
46
47
    public function getFrameworkAttribute(): string
48
    {
49
        return $this->attributes['framework']
50
            ?: config('genealabs-laravel-messenger.framework');
51
    }
52
53
    public function getMessageAttribute(): string
54
    {
55
        return $this->attributes['message'] ?: '';
56
    }
57
58
    public function getLevelAttribute(): string
59
    {
60
        return $this->attributes['level'] ?: 'info';
61
    }
62
63
    public function getTitleAttribute(): string
64
    {
65
        return $this->attributes['title'] ?: '';
66
    }
67
68
    public function getTypeAttribute(): string
69
    {
70
        return $this->attributes['type'] ?: 'alert';
71
    }
72
}
73