Completed
Push — master ( a52a56...4b8006 )
by Renato
09:08
created

ActivityLog::getIcon()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 6
c 1
b 0
f 0
nc 2
nop 0
dl 0
loc 11
rs 9.4285
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
     * @var array
27
     */
28
    protected $columns = [
29
        'action',
30
        'user_id',
31
        'description',
32
        'details',
33
        'ip_address',
34
        'content_type',
35
        'content_id',
36
        'created_at',
37
        'updated_at',
38
    ];
39
40
    /**
41
     * Get the icon class name for the log entry's action.
42
     *
43
     * @return string
44
     */
45
    public function getIcon()
46
    {
47
        $actionIcons = (array) config('nwlaravel.activity.action_icon');
48
        $icons = $actionIcons['icons'];
49
50
        if (empty($this->action) || !isset($icons[$this->action])) {
0 ignored issues
show
Documentation introduced by
The property action does not exist on object<NwLaravel\ActivityLog\ActivityLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
51
            return $icons['default'];
52
        }
53
54
        return $icons[$this->action];
0 ignored issues
show
Documentation introduced by
The property action does not exist on object<NwLaravel\ActivityLog\ActivityLog>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
55
    }
56
57
    /**
58
     * Get the markup for the log entry's icon.
59
     *
60
     * @return string
61
     */
62
    public function getIconMarkup()
63
    {
64
        $actionIcons = (array) config('nwlaravel.activity.action_icon');
65
        $iconElement = $actionIcons['element'];
66
        $iconPrefix = $actionIcons['class_prefix'];
67
        return sprintf('<%s class="%s%s"></%s>', $iconElement, $iconPrefix, $this->getIcon(), $iconElement);
68
    }
69
}
70