Passed
Push — master ( e5b31a...cf340d )
by Arthur
04:48
created

HasDatabaseNotifications   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A readNotifications() 0 4 1
A unreadNotifications() 0 4 1
A notifications() 0 9 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 14.10.18
6
 * Time: 18:37
7
 */
8
9
namespace Foundation\Traits;
10
11
trait HasDatabaseNotifications
12
{
13
    /**
14
     * Get the entity's notifications.
15
     */
16
    public function notifications()
17
    {
18
        if (env('DB_CONNECTION') === 'mongodb') {
19
            $notificationClass = \Foundation\Models\MongoDatabaseNotification::class;
20
        } else {
21
            $notificationClass = \Illuminate\Notifications\DatabaseNotification::class;
22
        }
23
        return $this->morphMany($notificationClass, 'notifiable')
0 ignored issues
show
Bug introduced by
It seems like morphMany() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

23
        return $this->/** @scrutinizer ignore-call */ morphMany($notificationClass, 'notifiable')
Loading history...
24
            ->orderBy('created_at', 'desc');
25
    }
26
27
    /**
28
     * Get the entity's read notifications.
29
     */
30
    public function readNotifications()
31
    {
32
        return $this->notifications()
33
            ->whereNotNull('read_at');
34
    }
35
36
    /**
37
     * Get the entity's unread notifications.
38
     */
39
    public function unreadNotifications()
40
    {
41
        return $this->notifications()
42
            ->whereNull('read_at');
43
    }
44
}
45