Passed
Pull Request — master (#721)
by Florian
02:44
created

Select2::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

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