InputSlider::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 7
nc 2
nop 12
dl 0
loc 17
ccs 9
cts 9
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 InputSlider extends InputGroupComponent
6
{
7
    use Traits\OldValueSupportTrait;
8
9
    /**
10
     * The bootstrap-slider plugin configuration parameters. Array with
11
     * 'key => value' pairs, where the key should be an existing configuration
12
     * property of the plugin.
13
     *
14
     * @var array
15
     */
16
    public $config;
17
18
    /**
19
     * The slider color. One of the available html colors.
20
     *
21
     * @var string
22
     */
23
    public $color;
24
25
    /**
26
     * Create a new component instance.
27
     * Note this component requires the 'bootstrap-slider' plugin.
28
     *
29
     * @return void
30
     */
31 3
    public function __construct(
32
        $name, $id = null, $label = null, $igroupSize = null, $labelClass = null,
33
        $fgroupClass = null, $igroupClass = null, $disableFeedback = null,
34
        $errorKey = null, $config = [], $color = null, $enableOldSupport = null
35
    ) {
36 3
        parent::__construct(
37 3
            $name, $id, $label, $igroupSize, $labelClass, $fgroupClass,
38 3
            $igroupClass, $disableFeedback, $errorKey
39 3
        );
40
41 3
        $this->config = is_array($config) ? $config : [];
42 3
        $this->enableOldSupport = isset($enableOldSupport);
43 3
        $this->color = $color;
44
45
        // Set a default plugin 'id' option.
46
47 3
        $this->config['id'] = $this->config['id'] ?? "{$this->id}-slider";
48
    }
49
50
    /**
51
     * Make the class attribute for the "input-group" element. Note we overwrite
52
     * the method of the parent class.
53
     *
54
     * @return string
55
     */
56 1
    public function makeInputGroupClass()
57
    {
58 1
        $classes = ['input-group'];
59
60 1
        if (isset($this->size) && in_array($this->size, ['sm', 'lg'])) {
61 1
            $classes[] = "input-group-{$this->size}";
62
        }
63
64 1
        if ($this->isInvalid()) {
65 1
            $classes[] = 'adminlte-invalid-islgroup';
66
        }
67
68 1
        if (isset($this->igroupClass)) {
69 1
            $classes[] = $this->igroupClass;
70
        }
71
72 1
        return implode(' ', $classes);
73
    }
74
75
    /**
76
     * Get the view / contents that represent the component.
77
     *
78
     * @return \Illuminate\View\View|string
79
     */
80 1
    public function render()
81
    {
82 1
        return view('adminlte::components.form.input-slider');
83
    }
84
}
85