Completed
Push — master ( fac72b...14ba86 )
by Faiq
14s
created

Common   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 42
rs 10
c 0
b 0
f 0
wmc 8

2 Methods

Rating   Name   Duplication   Size   Complexity  
B registerLog() 0 23 7
A currentUser() 0 3 1
1
<?php
2
3
namespace App;
4
5
use Illuminate\Support\Facades\Auth;
6
7
class Common
8
{
9
10
    /**
11
     * Register new activity log
12
     *
13
     * @param $data
14
     * @return bool
15
     */
16
    public static function registerLog($data) {
17
        $log = new Log;
18
19
        $log->action = $data['action'];
20
        $log->target = $data['target'];
21
        $log->prefix = $data['prefix'];
22
23
        switch($data['target']) {
24
            case 'thread'   : $log->thread_id = $data['target_id']; break;
25
            case 'article'  : $log->article_id = $data['target_id']; break;
26
        }
27
28
        switch ($data['actor']) {
29
            case 'admin'    : $log->admin_id = $data['actor_id'];   break;
30
            case 'doctor'   : $log->doctor_id = $data['actor_id'];  break;
31
            case 'user'     : $log->user_id = $data['actor_id'];  break;
32
        }
33
34
        if($log->save()) {
35
            return true;
36
        }
37
38
        return false;
39
    }
40
41
    /**
42
     * Get current logged in user
43
     *
44
     * @return mixed
45
     */
46
    public static function currentUser($guard)
47
    {
48
        return Auth::guard($guard)->user();
49
    }
50
51
}
52