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

InputSwitch   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 81
ccs 21
cts 21
cp 1
rs 10
c 1
b 0
f 0
wmc 12

4 Methods

Rating   Name   Duplication   Size   Complexity  
A makeInputGroupClass() 0 17 6
A __construct() 0 11 2
A makeItemClass() 0 9 3
A render() 0 3 1
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