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

Select2   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
dl 0
loc 57
ccs 13
cts 13
cp 1
rs 10
c 1
b 0
f 0
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A render() 0 3 1
A makeItemClass() 0 9 3
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, $inputGroupClass = null, $disableFeedback = null,
26
        $config = []
27
    ) {
28 2
        parent::__construct(
29 2
            $name, $label, $size, $labelClass, $topClass,
30
            $inputGroupClass, $disableFeedback
31
        );
32
33 2
        $this->config = is_array($config) ? $config : [];
34 2
        $this->config['theme'] = 'bootstrap4';
35 2
    }
36
37
    /**
38
     * Make the class attribute for the input group item.
39
     *
40
     * @param string $invalid
41
     * @return string
42
     */
43 1
    public function makeItemClass($invalid = null)
44
    {
45 1
        $classes = ['form-control'];
46
47 1
        if (! empty($invalid) && ! isset($this->disableFeedback)) {
48 1
            $classes[] = 'is-invalid';
49
        }
50
51 1
        return implode(' ', $classes);
52
    }
53
54
    /**
55
     * Get the view / contents that represent the component.
56
     *
57
     * @return \Illuminate\View\View|string
58
     */
59 1
    public function render()
60
    {
61 1
        return view('adminlte::components.select2');
62
    }
63
}
64