ActivityLog   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 82
ccs 12
cts 12
cp 1
rs 10
wmc 4
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getIcon() 0 12 3
A getIconMarkup() 0 7 1
1
<?php
2
namespace NwLaravel\ActivityLog;
3
4
use NwLaravel\Entities\AbstractEntity;
5
6
class ActivityLog extends AbstractEntity
7
{
8
    const CREATED  = 'created';
9
    const UPDATED  = 'updated';
10
    const DELETED  = 'deleted';
11
    const VIEW     = 'view';
12
    const LOGIN    = 'login';
13
    const LOGOUT   = 'logout';
14
    const EXECUTED = 'executed';
15
    const SEND     = 'send';
16
    const UPLOAD   = 'upload';
17
    const DOWNLOAD = 'download';
18
    const INFO     = 'info';
19
20
    /**
21
     * @var string
22
     */
23
    protected $table = "activity_log";
24
25
    /**
26
     * The attributes that are mass assignable.
27
     *
28
     * @var array
29
     */
30
    protected $fillable = [
31
        'action',
32
        'user_id',
33
        'user_type',
34
        'description',
35
        'details',
36
        'ip_address',
37
        'content_type',
38
        'content_id',
39
    ];
40
41
    /**
42
     * @var array
43
     */
44
    protected $columns = [
45
        'action',
46
        'user_id',
47
        'user_type',
48
        'description',
49
        'details',
50
        'ip_address',
51
        'content_type',
52
        'content_id',
53
        'created_at',
54
        'updated_at',
55
    ];
56
57
    /**
58
     * Get the icon class name for the log entry's action.
59
     *
60
     * @return string
61
     */
62 13
    public function getIcon()
63
    {
64 13
        $actionIcons = (array) config('nwlaravel.activity.action_icon');
65 13
        $icons = $actionIcons['icons'];
66 13
        $action = $this->getAttribute('action');
67
        
68 13
        if (empty($action) || !isset($icons[$action])) {
69 1
            return $icons['default'];
70
        }
71
72 12
        return $icons[$action];
73
    }
74
75
    /**
76
     * Get the markup for the log entry's icon.
77
     *
78
     * @return string
79
     */
80 13
    public function getIconMarkup()
81
    {
82 13
        $actionIcons = (array) config('nwlaravel.activity.action_icon');
83 13
        $iconElement = $actionIcons['element'];
84 13
        $iconPrefix = $actionIcons['class_prefix'];
85 13
        return sprintf('<%s class="%s%s"></%s>', $iconElement, $iconPrefix, $this->getIcon(), $iconElement);
86
    }
87
}
88