Completed
Push — master ( 01fbcc...2b2636 )
by vistart
06:24
created

NotificationReadTrait::read()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
ccs 0
cts 6
cp 0
rs 9.4285
cc 2
eloc 5
nc 2
nop 2
crap 6
1
<?php
2
3
/**
4
 *  _   __ __ _____ _____ ___  ____  _____
5
 * | | / // // ___//_  _//   ||  __||_   _|
6
 * | |/ // /(__  )  / / / /| || |     | |
7
 * |___//_//____/  /_/ /_/ |_||_|     |_|
8
 * @link https://vistart.name/
9
 * @copyright Copyright (c) 2016 vistart
10
 * @license https://vistart.name/license/
11
 */
12
13
namespace vistart\Models\traits;
14
15
/**
16
 * Description of NotificationLog
17
 *
18
 * @author vistart <[email protected]>
19
 */
20
trait NotificationReadTrait
21
{
22
23
    public static function read($user, $notification)
24
    {
25
        $log = static::find()->byIdentity($user)->id($notification->guid)->one();
26
        if (!$log) {
27
            $log = $user->create(static::className(), ['id' => $notification->guid]);
28
        }
29
        return $log->save();
30
    }
31
32
    public static function unread($user, $notification)
33
    {
34
        $log = static::find()->byIdentity($user)->id($notification - guid)->one();
35
        if ($log) {
36
            return $log->delete();
37
        }
38
        return true;
39
    }
40
}
41