TrackedNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 32
c 0
b 0
f 0
rs 10
ccs 11
cts 11
cp 1
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A channels() 0 3 1
A newFactory() 0 3 1
A boot() 0 6 1
A getTable() 0 3 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