Passed
Pull Request — master (#888)
by Diego
02:36
created

NavbarNotificationLink::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
nc 2
nop 7
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components\Layout;
4
5
use Illuminate\View\Component;
6
7
class NavbarNotificationLink extends Component
8
{
9
    /**
10
     * The id attribute for the underlying <li> wrapper.
11
     *
12
     * @var string
13
     */
14
    public $id;
15
16
    /**
17
     * The notification icon (a Font Awesome icon).
18
     *
19
     * @var string
20
     */
21
    public $icon;
22
23
    /**
24
     * The notification icon color (an AdminLTE color).
25
     *
26
     * @var string
27
     */
28
    public $iconColor;
29
30
    /**
31
     * The label for the notification badge.
32
     *
33
     * @var string
34
     */
35
    public $badgeLabel;
36
37
    /**
38
     * The background color for the notification badge (an AdminLTE color).
39
     *
40
     * @var string
41
     */
42
    public $badgeColor;
43
44
    /**
45
     * The url to query for new data in order to update the notification.
46
     *
47
     * @var string
48
     */
49
    public $updateUrl;
50
51
    /**
52
     * The time interval (in seconds) for query the update url.
53
     *
54
     * @var integer
55
     */
56
    public $updateTime;
57
58
    /**
59
     * Create a new component instance.
60
     *
61
     * @return void
62
     */
63 2
    public function __construct(
64
        $id, $icon, $iconColor = null, $badgeLabel = null, $badgeColor = null,
65
        $updateUrl = null, $updateTime = null
66
    ) {
67 2
        $this->id = $id;
68 2
        $this->icon = $icon;
69 2
        $this->iconColor = $iconColor;
70 2
        $this->badgeLabel = $badgeLabel;
71 2
        $this->badgeColor = $badgeColor;
72 2
        $this->updateUrl = $updateUrl;
73 2
        $this->updateTime = isset($updateTime) ? intval($updateTime) : 0;
74 2
    }
75
76
    /**
77
     * Make the class attribute for the notification icon.
78
     *
79
     * @return string
80
     */
81 1
    public function makeIconClass()
82
    {
83 1
        $classes = [$this->icon];
84
85 1
        if (! empty($this->iconColor)) {
86 1
            $classes[] = "text-{$this->iconColor}";
87
        }
88
89 1
        return implode(' ', $classes);
90
    }
91
92
    /**
93
     * Make the class attribute for the notification badge.
94
     *
95
     * @return string
96
     */
97 1
    public function makeBadgeClass()
98
    {
99 1
        $classes = ['badge navbar-badge text-bold text-xs badge-pill'];
100
101 1
        if (! empty($this->badgeColor)) {
102 1
            $classes[] = "badge-{$this->badgeColor}";
103
        }
104
105 1
        return implode(' ', $classes);
106
    }
107
108
    /**
109
     * Get the view / contents that represent the component.
110
     *
111
     * @return \Illuminate\View\View|string
112
     */
113 1
    public function render()
114
    {
115 1
        return view('adminlte::components.layout.navbar-notification-link');
116
    }
117
}
118