Passed
Pull Request — master (#721)
by Florian
03:05
created

SelectBs::makeItemClass()   A

Complexity

Conditions 5
Paths 4

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 7
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 17
ccs 8
cts 8
cp 1
crap 5
rs 9.6111
1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\Components;
4
5
class SelectBs extends inputGroupComponent
6
{
7
    /**
8
     * The bootstrap-select plugin configuration parameters. Array with
9
     * key => value pairs, where the key should be an existing configuration
10
     * property of the bootstrap-select plugin.
11
     *
12
     * @var array
13
     */
14
    public $config;
15
16
    /**
17
     * Create a new component instance.
18
     * Note this component requires the 'bootstrap-select' plugin.
19
     *
20
     * @return void
21
     */
22 2
    public function __construct(
23
        $name, $label = null, $size = null, $labelClass = null,
24
        $topClass = null, $disableFeedback = null, $config = []
25
    ) {
26 2
        parent::__construct(
27 2
            $name, $label, $size, $labelClass, $topClass, $disableFeedback
28
        );
29
30 2
        $this->config = is_array($config) ? $config : [];
31 2
    }
32
33
    /**
34
     * Make the class attribute for the input group item.
35
     *
36
     * @param string $invalid
37
     * @return string
38
     */
39 1
    public function makeItemClass($invalid)
40
    {
41 1
        $classes = ['form-control'];
42
43 1
        if (! empty($invalid) && ! isset($this->disableFeedback)) {
44 1
            $classes[] = 'is-invalid';
45
        }
46
47
        // The next workaround setups the plugin when using sm/lg sizes.
48
        // Note: this may change with newer plugin versions.
49
50 1
        if (isset($this->size) && in_array($this->size, ['sm', 'lg'])) {
51 1
            $classes[] = "form-control-{$this->size}";
52 1
            $classes[] = 'p-0';
53
        }
54
55 1
        return implode(' ', $classes);
56
    }
57
58
    /**
59
     * Get the view / contents that represent the component.
60
     *
61
     * @return \Illuminate\View\View|string
62
     */
63 1
    public function render()
64
    {
65 1
        return view('adminlte::components.select-bs');
66
    }
67
}
68