Passed
Pull Request — master (#1151)
by Diego
03:33
created

InfoBox   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 128
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 28
dl 0
loc 128
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A makeBoxClass() 0 9 2
A __construct() 0 19 2
A makeIconClass() 0 9 2
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 InfoBox extends Component
9
{
10
    /**
11
     * The title/header for the box.
12
     *
13
     * @var string
14
     */
15
    public $title;
16
17
    /**
18
     * A short text description for the box.
19
     *
20
     * @var string
21
     */
22
    public $text;
23
24
    /**
25
     * A long description for the box.
26
     *
27
     * @var string
28
     */
29
    public $description;
30
31
    /**
32
     * A Font Awesome icon for the box.
33
     *
34
     * @var string
35
     */
36
    public $icon;
37
38
    /**
39
     * The box theme (light, dark, primary, secondary, info, success, warning,
40
     * danger or any other AdminLTE color like lighblue or teal).
41
     *
42
     * @var string
43
     */
44
    public $theme;
45
46
    /**
47
     * The icon theme (light, dark, primary, secondary, info, success, warning,
48
     * danger or any other AdminLTE color like lighblue or teal).
49
     *
50
     * @var string
51
     */
52
    public $iconTheme;
53
54
    /**
55
     * Enables a progress bar for the box. The value should be an integer
56
     * indicating the percentage of the progress bar.
57
     *
58
     * @var int
59
     */
60
    public $progress;
61
62
    /**
63
     * The progress bar theme (light, dark, primary, secondary, info, success,
64
     * warning, danger or any other AdminLTE color like lighblue or teal).
65
     *
66
     * @var string
67
     */
68
    public $progressTheme;
69
70
    /**
71
     * Create a new component instance.
72
     *
73
     * @return void
74
     */
75 2
    public function __construct(
76
        $title = null, $text = null, $icon = null, $description = null,
77
        $theme = null, $iconTheme = null, $progress = null,
78
        $progressTheme = 'white'
79
    ) {
80 2
        $this->title = UtilsHelper::applyHtmlEntityDecoder($title);
81 2
        $this->text = UtilsHelper::applyHtmlEntityDecoder($text);
82 2
        $this->icon = $icon;
83 2
        $this->description = UtilsHelper::applyHtmlEntityDecoder($description);
84 2
        $this->theme = $theme;
85 2
        $this->iconTheme = $iconTheme;
86 2
87 2
        // Setup the progress property, to be between 0 and 100 when defined.
88
89
        $this->progress = isset($progress)
90
            ? max(min($progress, 100), 0)
91
            : null;
92
93
        $this->progressTheme = $progressTheme;
94
    }
95 1
96
    /**
97 1
     * Make the box class.
98
     *
99 1
     * @return string
100 1
     */
101
    public function makeBoxClass()
102
    {
103 1
        $classes = ['info-box'];
104
105
        if (isset($this->theme)) {
106
            $classes[] = "bg-{$this->theme}";
107
        }
108
109
        return implode(' ', $classes);
110
    }
111 1
112
    /**
113 1
     * Make the icon container class.
114
     *
115 1
     * @return string
116 1
     */
117
    public function makeIconClass()
118
    {
119 1
        $classes = ['info-box-icon'];
120
121
        if (isset($this->iconTheme)) {
122
            $classes[] = "bg-{$this->iconTheme}";
123
        }
124
125
        return implode(' ', $classes);
126
    }
127 1
128
    /**
129 1
     * Get the view / contents that represent the component.
130
     *
131
     * @return \Illuminate\View\View|string
132
     */
133
    public function render()
134
    {
135
        return view('adminlte::components.widget.info-box');
136
    }
137
}
138