Alert::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 6
nc 2
nop 4
dl 0
loc 13
ccs 7
cts 7
cp 1
crap 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Widget;
4
5
use Illuminate\View\Component;
6
use JeroenNoten\LaravelAdminLte\Helpers\UtilsHelper;
7
8
class Alert extends Component
9
{
10
    /**
11
     * The default icon for each alert theme.
12
     *
13
     * @var array
14
     */
15
    protected $icons = [
16
        'dark' => 'fas fa-bolt',
17
        'light' => 'far fa-lightbulb',
18
        'primary' => 'fas fa-bell',
19
        'secondary' => 'fas fa-tag',
20
        'info' => 'fas fa-info-circle',
21
        'success' => 'fas fa-check-circle',
22
        'warning' => 'fas fa-exclamation-triangle',
23
        'danger' => 'fas fa-ban',
24
    ];
25
26
    /**
27
     * The alert icon (a Font Awesome icon).
28
     *
29
     * @var string
30
     */
31
    public $icon;
32
33
    /**
34
     * The alert theme (dark, light, primary, secondary, info, success, warning
35
     * or danger).
36
     *
37
     * @var string
38
     */
39
    public $theme;
40
41
    /**
42
     * The alert title.
43
     *
44
     * @var string
45
     */
46
    public $title;
47
48
    /**
49
     * Indicates if the alert is dismissable.
50
     *
51
     * @var bool|mixed
52
     */
53
    public $dismissable;
54
55
    /**
56
     * Create a new component instance.
57
     *
58
     * @return void
59
     */
60 3
    public function __construct(
61
        $theme = null, $icon = null, $title = null, $dismissable = null
62
    ) {
63 3
        $this->theme = $theme;
64 3
        $this->icon = $icon;
65 3
        $this->title = UtilsHelper::applyHtmlEntityDecoder($title);
66 3
        $this->dismissable = $dismissable;
67
68
        // When a theme is provided, use the default theme icon if no other
69
        // icon is provided.
70
71 3
        if (! isset($icon) && ! empty($theme)) {
72 1
            $this->icon = $this->icons[$theme];
73
        }
74
    }
75
76
    /**
77
     * Make the class attribute for the alert item.
78
     *
79
     * @return string
80
     */
81 2
    public function makeAlertClass()
82
    {
83 2
        $classes = ['alert'];
84
85 2
        if (! empty($this->theme)) {
86 1
            $classes[] = "alert-{$this->theme}";
87
        } else {
88 1
            $classes[] = 'border';
89
        }
90
91 2
        if (! empty($this->dismissable)) {
92 1
            $classes[] = 'alert-dismissable';
93
        }
94
95 2
        return implode(' ', $classes);
96
    }
97
98
    /**
99
     * Get the view / contents that represent the component.
100
     *
101
     * @return \Illuminate\View\View|string
102
     */
103 1
    public function render()
104
    {
105 1
        return view('adminlte::components.widget.alert');
106
    }
107
}
108