ProfileRowItem::makeTextWrapperClass()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 8
nc 3
nop 0
dl 0
loc 14
ccs 9
cts 9
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 ProfileRowItem extends Component
9
{
10
    /**
11
     * The title/header for the item.
12
     *
13
     * @var string
14
     */
15
    public $title;
16
17
    /**
18
     * The text/description for the item.
19
     *
20
     * @var string
21
     */
22
    public $text;
23
24
    /**
25
     * An extra tooltip for the text of the item.
26
     *
27
     * @var string
28
     */
29
    public $textTooltip;
30
31
    /**
32
     * A Font Awesome icon for the item.
33
     *
34
     * @var string
35
     */
36
    public $icon;
37
38
    /**
39
     * The item size. Used to wrap the item inside a col-size div.
40
     *
41
     * @var int
42
     */
43
    public $size;
44
45
    /**
46
     * The badge theme for the text attribute. When used, the text attribute
47
     * will be wrapped inside a badge of the configured theme. Available themes
48
     * are: light, dark, primary, secondary, info, success, warning, danger or
49
     * any other AdminLTE color like lighblue or teal. You can also prepend
50
     * the 'pill-' token for a pill badge, for example: 'pill-info'.
51
     *
52
     * @var string
53
     */
54
    public $badge;
55
56
    /**
57
     * Setup an url for the item. When enabled the title attribute will be
58
     * wrapped inside a link pointing to that url.
59
     *
60
     * @var string
61
     */
62
    public $url;
63
64
    /**
65
     * The target element for the URL (title or text).
66
     *
67
     * @var string
68
     */
69
    public $urlTarget;
70
71
    /**
72
     * Create a new component instance.
73
     *
74
     * @return void
75
     */
76 2
    public function __construct(
77
        $title = null, $text = null, $icon = null, $size = 12,
78
        $badge = null, $url = null, $urlTarget = 'title',
79
        $textTooltip = null
80
    ) {
81 2
        $this->title = UtilsHelper::applyHtmlEntityDecoder($title);
82 2
        $this->text = UtilsHelper::applyHtmlEntityDecoder($text);
83 2
        $this->textTooltip = UtilsHelper::applyHtmlEntityDecoder($textTooltip);
84 2
        $this->icon = $icon;
85 2
        $this->size = $size;
86 2
        $this->badge = $badge;
87 2
        $this->url = $url;
88 2
        $this->urlTarget = $urlTarget;
89
    }
90
91
    /**
92
     * Make the text wrapper class.
93
     *
94
     * @return string
95
     */
96 1
    public function makeTextWrapperClass()
97
    {
98 1
        $classes = ['float-right'];
99
100 1
        if (isset($this->badge)) {
101 1
            $badgeMode = str_starts_with($this->badge, 'pill-')
102 1
                ? 'badge-pill'
103 1
                : 'badge';
104
105 1
            $badgeTheme = str_replace('pill-', '', $this->badge);
106 1
            $classes[] = "{$badgeMode} bg-{$badgeTheme}";
107
        }
108
109 1
        return implode(' ', $classes);
110
    }
111
112
    /**
113
     * Get the view / contents that represent the component.
114
     *
115
     * @return \Illuminate\View\View|string
116
     */
117 1
    public function render()
118
    {
119 1
        return view('adminlte::components.widget.profile-row-item');
120
    }
121
}
122