Completed
Push — master ( 19d7ee...88c02d )
by wen
06:28
created

Factory::web()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 6
nc 1
nop 3
1
<?php
2
3
namespace Sco\ActionLog;
4
5
use Sco\ActionLog\Models\ActionLogModel;
6
7
class Factory
8
{
9
10
    /**
11
     * Logging Action
12
     *
13
     * @param \Sco\ActionLog\LogInfo $info
14
     *
15
     * @return bool
16
     */
17
    public static function info(LogInfo $info)
18
    {
19
        $log = new ActionLogModel();
20
21
        if (!$info->getUserId() && !config('actionlog.guest')) {
22
            return false;
23
        }
24
25
        $content = $info->getContent();
26
        $client  = $info->getClient();
27
28
        $userKey = config('actionlog.user_foreign_key');
29
30
        $log->$userKey  = $info->getUserId();
31
        $log->type      = $info->getType();
32
        $log->content   = is_string($content) ? $content : json_encode($content);
33
        $log->client_ip = $info->getClientIp();
34
        $log->client    = is_string($client) ? $client : json_encode($client);
35
        $log->save();
36
37
        return true;
38
    }
39
40
41
    public function __call($method, $parameters)
42
    {
43
        return (new ActionLogModel)->$method(...$parameters);
44
    }
45
46
47
    public static function __callStatic($method, $parameters)
48
    {
49
        return (new static)->$method(...$parameters);
50
    }
51
}
52