Factory   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 3
dl 0
loc 46
c 0
b 0
f 0
rs 10

3 Methods

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