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

InputSlider   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 18
dl 0
loc 75
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 9

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 16 2
A makeInputGroupClass() 0 17 6
A render() 0 3 1
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Form;
4
5
class InputSlider extends InputGroupComponent
6
{
7
    /**
8
     * The bootstrap-slider plugin configuration parameters. Array with
9
     * key => value pairs, where the key should be an existing configuration
10
     * property of the plugin.
11
     *
12
     * @var array
13
     */
14
    public $config;
15
16
    /**
17
     * The slider color. One of the available html colors.
18
     *
19
     * @var string
20
     */
21
    public $color;
22
23
    /**
24
     * Create a new component instance.
25
     * Note this component requires the 'bootstrap-slider' plugin.
26
     *
27
     * @return void
28
     */
29 2
    public function __construct(
30
        $name, $id = null, $label = null, $igroupSize = null, $labelClass = null,
31
        $fgroupClass = null, $igroupClass = null, $disableFeedback = null,
32
        $errorKey = null, $config = [], $color = null
33
    ) {
34 2
        parent::__construct(
35 2
            $name, $id, $label, $igroupSize, $labelClass, $fgroupClass,
36
            $igroupClass, $disableFeedback, $errorKey
37
        );
38
39 2
        $this->config = is_array($config) ? $config : [];
40 2
        $this->color = $color;
41
42
        // Set a default plugin 'id' option.
43
44 2
        $this->config['id'] = $this->config['id'] ?? "{$this->id}-slider";
45 2
    }
46
47
    /**
48
     * Make the class attribute for the "input-group" element. Note we overwrite
49
     * the method of the parent class.
50
     *
51
     * @return string
52
     */
53 1
    public function makeInputGroupClass()
54
    {
55 1
        $classes = ['input-group'];
56
57 1
        if (isset($this->size) && in_array($this->size, ['sm', 'lg'])) {
58 1
            $classes[] = "input-group-{$this->size}";
59
        }
60
61 1
        if ($this->isInvalid() && ! isset($this->disableFeedback)) {
62 1
            $classes[] = 'adminlte-invalid-islgroup';
63
        }
64
65 1
        if (isset($this->igroupClass)) {
66 1
            $classes[] = $this->igroupClass;
67
        }
68
69 1
        return implode(' ', $classes);
70
    }
71
72
    /**
73
     * Get the view / contents that represent the component.
74
     *
75
     * @return \Illuminate\View\View|string
76
     */
77 1
    public function render()
78
    {
79 1
        return view('adminlte::components.form.input-slider');
80
    }
81
}
82