Passed
Push — master ( 8f6522...eef865 )
by Florian
06:34
created

Progress::render()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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
7
class Progress extends Component
8
{
9
    /**
10
     * The available progress bar sizes.
11
     *
12
     * @var array
13
     */
14
    protected $pSizes = ['sm', 'xs', 'xxs'];
15
16
    /**
17
     * The progress bar percentage value (integer between 0 and 100).
18
     *
19
     * @var int
20
     */
21
    public $value;
22
23
    /**
24
     * The progress bar theme (light, dark, primary, secondary, info, success,
25
     * warning, danger or any other AdminLTE color like lighblue or teal).
26
     *
27
     * @var string
28
     */
29
    public $theme;
30
31
    /**
32
     * The progress bar size (sm, xs or xxs).
33
     *
34
     * @var string
35
     */
36
    public $size;
37
38
    /**
39
     * Indicates if the progress bar have stripes.
40
     *
41
     * @var bool|mixed
42
     */
43
    public $striped;
44
45
    /**
46
     * Indicates if the progress bar is animated.
47
     *
48
     * @var bool|mixed
49
     */
50
    public $animated;
51
52
    /**
53
     * Indicates if the progress bar is vertical.
54
     *
55
     * @var bool|mixed
56
     */
57
    public $vertical;
58
59
    /**
60
     * Enables the progress bar label.
61
     *
62
     * @var bool|mixed
63
     */
64
    public $withLabel;
65
66
    /**
67
     * Create a new component instance.
68
     *
69
     * @return void
70
     */
71 2
    public function __construct(
72
        $value = 0, $theme = 'info', $size = null, $striped = null,
73
        $vertical = null, $animated = null, $withLabel = null
74
    ) {
75
        // Control and setup the value property.
76
77 2
        $this->value = ($value >= 0 && $value <= 100) ? $value : 0;
78
79
        // Initialize other properties.
80
81 2
        $this->theme = $theme;
82 2
        $this->size = $size;
83 2
        $this->striped = $striped;
84 2
        $this->animated = $animated;
85 2
        $this->vertical = $vertical;
86 2
        $this->withLabel = $withLabel;
87 2
    }
88
89
    /**
90
     * Make the class attribute for the main progress item.
91
     *
92
     * @return string
93
     */
94 1
    public function makeProgressClass()
95
    {
96 1
        $classes = ['progress'];
97
98 1
        if (isset($this->size) && in_array($this->size, $this->pSizes)) {
99 1
            $classes[] = "progress-{$this->size}";
100
        }
101
102 1
        if (isset($this->vertical)) {
103 1
            $classes[] = 'vertical';
104
        }
105
106 1
        return implode(' ', $classes);
107
    }
108
109
    /**
110
     * Make the class attribute for the progress bar item.
111
     *
112
     * @return string
113
     */
114 1
    public function makeProgressBarClass()
115
    {
116 1
        $classes = ['progress-bar', 'text-bold'];
117
118 1
        if (! empty($this->theme)) {
119 1
            $classes[] = "bg-{$this->theme}";
120
        }
121
122 1
        if (isset($this->striped) || isset($this->animated)) {
123 1
            $classes[] = 'progress-bar-striped';
124
        }
125
126 1
        if (isset($this->animated)) {
127 1
            $classes[] = 'progress-bar-animated';
128
        }
129
130 1
        return implode(' ', $classes);
131
    }
132
133
    /**
134
     * Make the style attribute for the progress bar item.
135
     *
136
     * @return string
137
     */
138 1
    public function makeProgressBarStyle()
139
    {
140 1
        $styles = [];
141
142 1
        if (isset($this->vertical)) {
143 1
            $styles[] = "height:{$this->value}%";
144
        } else {
145 1
            $styles[] = "width:{$this->value}%";
146
        }
147
148 1
        return implode(';', $styles);
149
    }
150
151
    /**
152
     * Get the view / contents that represent the component.
153
     *
154
     * @return \Illuminate\View\View|string
155
     */
156 1
    public function render()
157
    {
158 1
        return view('adminlte::components.widget.progress');
159
    }
160
}
161