Passed
Pull Request — master (#856)
by Florian
03:57
created

InputSwitch::makeInputGroupClass()   A

Complexity

Conditions 6
Paths 8

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 6

Importance

Changes 0
Metric Value
cc 6
eloc 8
nc 8
nop 1
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 6
rs 9.2222
c 0
b 0
f 0
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components;
4
5
class InputSwitch extends InputGroupComponent
6
{
7
    /**
8
     * The Bootstrap Switch 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
     * Create a new component instance.
18
     * Note this component requires the 'Bootstrap Switch' plugin.
19
     *
20
     * @return void
21
     */
22 2
    public function __construct(
23
        $name, $label = null, $size = null, $labelClass = null,
24
        $topClass = null, $inputGroupClass = null, $disableFeedback = null,
25
        $config = []
26
    ) {
27 2
        parent::__construct(
28 2
            $name, $label, $size, $labelClass, $topClass,
29
            $inputGroupClass, $disableFeedback
30
        );
31
32 2
        $this->config = is_array($config) ? $config : [];
33 2
    }
34
35
    /**
36
     * Make the class attribute for the "input-group" element. Note we overwrite
37
     * the method of the parent class.
38
     *
39
     * @param string $invalid
40
     * @return string
41
     */
42 1
    public function makeInputGroupClass($invalid = null)
43
    {
44 1
        $classes = ['input-group'];
45
46 1
        if (isset($this->size) && in_array($this->size, ['sm', 'lg'])) {
47 1
            $classes[] = "input-group-{$this->size}";
48
        }
49
50 1
        if (! empty($invalid) && ! isset($this->disableFeedback)) {
51 1
            $classes[] = 'adminlte-invalid-iswgroup';
52
        }
53
54 1
        if (isset($this->inputGroupClass)) {
55 1
            $classes[] = $this->inputGroupClass;
56
        }
57
58 1
        return implode(' ', $classes);
59
    }
60
61
    /**
62
     * Make the class attribute for the input group item.
63
     *
64
     * @param string $invalid
65
     * @return string
66
     */
67 1
    public function makeItemClass($invalid = null)
68
    {
69 1
        $classes = [];
70
71 1
        if (! empty($invalid) && ! isset($this->disableFeedback)) {
72 1
            $classes[] = 'is-invalid';
73
        }
74
75 1
        return implode(' ', $classes);
76
    }
77
78
    /**
79
     * Get the view / contents that represent the component.
80
     *
81
     * @return \Illuminate\View\View|string
82
     */
83 1
    public function render()
84
    {
85 1
        return view('adminlte::components.input-switch');
86
    }
87
}
88