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

MongoDatabaseNotification::unread()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 3
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 14.10.18
6
 * Time: 18:34
7
 */
8
9
namespace Foundation\Models;
10
11
12
use Illuminate\Notifications\DatabaseNotificationCollection;
13
use Jenssegers\Mongodb\Eloquent\Model;
14
15
class MongoDatabaseNotification extends Model
16
{
17
    /**
18
     * Indicates if the IDs are auto-incrementing.
19
     *
20
     * @var bool
21
     */
22
    public $incrementing = false;
23
    /**
24
     * The table associated with the model.
25
     *
26
     * @var string
27
     */
28
    protected $collection = 'notifications';
29
    /**
30
     * The guarded attributes on the model.
31
     *
32
     * @var array
33
     */
34
    protected $guarded = [];
35
    /**
36
     * The attributes that should be cast to native types.
37
     *
38
     * @var array
39
     */
40
    protected $casts = [
41
        'data' => 'array',
42
        'read_at' => 'datetime',
43
    ];
44
    /**
45
     * Get the notifiable entity that the notification belongs to.
46
     */
47
    public function notifiable()
48
    {
49
        return $this->morphTo();
50
    }
51
    /**
52
     * Mark the notification as read.
53
     *
54
     * @return void
55
     */
56
    public function markAsRead()
57
    {
58
        if (is_null($this->read_at)) {
0 ignored issues
show
Bug introduced by
The property read_at does not seem to exist on Foundation\Models\MongoDatabaseNotification. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
59
            $this->forceFill(['read_at' => $this->freshTimestamp()])->save();
60
        }
61
    }
62
    /**
63
     * Determine if a notification has been read.
64
     *
65
     * @return bool
66
     */
67
    public function read()
68
    {
69
        return $this->read_at !== null;
0 ignored issues
show
Bug introduced by
The property read_at does not seem to exist on Foundation\Models\MongoDatabaseNotification. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
70
    }
71
    /**
72
     * Determine if a notification has not been read.
73
     *
74
     * @return bool
75
     */
76
    public function unread()
77
    {
78
        return $this->read_at === null;
0 ignored issues
show
Bug introduced by
The property read_at does not seem to exist on Foundation\Models\MongoDatabaseNotification. Are you sure there is no database migration missing?

Checks if undeclared accessed properties appear in database migrations and if the creating migration is correct.

Loading history...
79
    }
80
    /**
81
     * Create a new database notification collection instance.
82
     *
83
     * @param  array  $models
84
     * @return \Illuminate\Notifications\DatabaseNotificationCollection
85
     */
86
    public function newCollection(array $models = [])
87
    {
88
        return new DatabaseNotificationCollection($models);
89
    }
90
}
91