Passed
Pull Request — master (#1022)
by Diego
02:37
created

Select2::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 6
nc 2
nop 11
dl 0
loc 13
ccs 6
cts 6
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 Select2 extends InputGroupComponent
6
{
7
    use Traits\OldValueSupportTrait;
8
9
    /**
10
     * The select2 plugin configuration parameters. Array with key => value
11
     * pairs, where the key should be an existing configuration property of
12
     * the select2 plugin.
13
     *
14
     * @var array
15
     */
16
    public $config;
17
18
    /**
19
     * Create a new component instance.
20
     * Note this component requires the 'select2' plugin and the 'bootstrap4'
21
     * css theme.
22
     *
23
     * @return void
24
     */
25 3
    public function __construct(
26
        $name, $id = null, $label = null, $igroupSize = null, $labelClass = null,
27
        $fgroupClass = null, $igroupClass = null, $disableFeedback = null,
28
        $errorKey = null, $config = [], $enableOldSupport = null
29
    ) {
30 3
        parent::__construct(
31 3
            $name, $id, $label, $igroupSize, $labelClass, $fgroupClass,
32
            $igroupClass, $disableFeedback, $errorKey
33
        );
34
35 3
        $this->config = is_array($config) ? $config : [];
36 3
        $this->config['theme'] = 'bootstrap4';
37 3
        $this->enableOldSupport = isset($enableOldSupport);
38 3
    }
39
40
    /**
41
     * Get the view / contents that represent the component.
42
     *
43
     * @return \Illuminate\View\View|string
44
     */
45 1
    public function render()
46
    {
47 1
        return view('adminlte::components.form.select2');
48
    }
49
}
50