Passed
Push — master ( 8f6522...eef865 )
by Florian
06:34
created

SelectBs::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 10
dl 0
loc 11
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
namespace JeroenNoten\LaravelAdminLte\View\Components\Form;
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, $id = null, $label = null, $igroupSize = null, $labelClass = null,
24
        $fgroupClass = null, $igroupClass = null, $disableFeedback = null,
25
        $errorKey = null, $config = []
26
    ) {
27 2
        parent::__construct(
28 2
            $name, $id, $label, $igroupSize, $labelClass, $fgroupClass,
29
            $igroupClass, $disableFeedback, $errorKey
30
        );
31
32 2
        $this->config = is_array($config) ? $config : [];
33 2
    }
34
35
    /**
36
     * Make the class attribute for the input group item.
37
     *
38
     * @return string
39
     */
40 1
    public function makeItemClass()
41
    {
42 1
        $classes = ['form-control'];
43
44 1
        if ($this->isInvalid() && ! isset($this->disableFeedback)) {
45 1
            $classes[] = 'is-invalid';
46
        }
47
48
        // The next workaround setups the plugin when using sm/lg sizes.
49
        // Note: this may change with newer plugin versions.
50
51 1
        if (isset($this->size) && in_array($this->size, ['sm', 'lg'])) {
52 1
            $classes[] = "form-control-{$this->size}";
53 1
            $classes[] = 'p-0';
54
        }
55
56 1
        return implode(' ', $classes);
57
    }
58
59
    /**
60
     * Get the view / contents that represent the component.
61
     *
62
     * @return \Illuminate\View\View|string
63
     */
64 1
    public function render()
65
    {
66 1
        return view('adminlte::components.form.select-bs');
67
    }
68
}
69