TrackedNotification::boot()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 3
nc 1
nop 0
dl 0
loc 6
c 0
b 0
f 0
cc 1
rs 10
ccs 4
cts 4
cp 1
crap 1
1
<?php
2
3
namespace NotificationTracker\Models;
4
5
use Illuminate\Database\Eloquent\Factories\HasFactory;
6
use Illuminate\Database\Eloquent\Model;
7
use Illuminate\Database\Eloquent\Relations\HasMany;
8
use JsonFieldCast\Casts\SimpleJsonField;
9
use NotificationTracker\Database\Factories\TrackedNotificationFactory;
10
use NotificationTracker\NotificationTracker;
11
12
/**
13
 * @property \JsonFieldCast\Json\SimpleJsonField $meta
14
 */
15
class TrackedNotification extends Model
16
{
17
    use HasFactory;
18
19
    protected $guarded = [];
20
21
    protected $casts = [
22
        'meta' => SimpleJsonField::class,
23
    ];
24
25 9
    public function getTable(): string
26
    {
27 9
        return config('notification-tracker.tables.notifications');
28
    }
29
30 9
    protected static function boot(): void
31
    {
32 9
        parent::boot();
33
34 9
        static::deleting(function ($model) {
35 1
            $model->channels->each(fn ($channel) => $channel->delete());
36 9
        });
37
    }
38
39 5
    protected static function newFactory(): TrackedNotificationFactory
40
    {
41 5
        return TrackedNotificationFactory::new();
42
    }
43
44 6
    public function channels(): HasMany
45
    {
46 6
        return $this->hasMany(NotificationTracker::modelClass('channel'), 'notification_id', 'id');
47
    }
48
}
49