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

NotificationReadTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 21
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 21
ccs 0
cts 11
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A read() 0 8 2
A unread() 0 8 2
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