Passed
Pull Request — master (#863)
by Diego
03:31
created

Alert   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 98
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 7

3 Methods

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