Completed
Push — master ( 314952...32a7b8 )
by wen
01:54
created

Factory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A event() 0 9 1
A info() 0 14 4
1
<?php
2
3
namespace Sco\ActionLog;
4
5
use Auth;
6
use Sco\ActionLog\Events\AbstractEvent;
7
use Sco\ActionLog\Models\ActionLog;
8
9
class Factory
10
{
11
    public function event(AbstractEvent $event)
12
    {
13
        $this->info(
14
            $event->type,
15
            $event->model->getOriginal(),
16
            $event->model->getTable(),
17
            $event->userId
18
        );
19
    }
20
21
    public function info($type, $content, $tableName = '', $userId = null)
22
    {
23
        $log = new ActionLog();
24
25
        $log->user_id = $userId ?: (Auth::id() ? Auth::id() : 0);
26
27
        $log->type       = $type;
28
        $log->table_name = $tableName;
29
        $log->content    = is_array($content) ? json_encode($content) : $content;
30
31
        $log->ip = request()->getClientIp();
32
33
        $log->save();
34
    }
35
}
36