Passed
Pull Request — master (#721)
by Florian
05:48
created

InputSlider::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 8
dl 0
loc 14
ccs 6
cts 6
cp 1
crap 2
rs 10
c 2
b 1
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\Components;
4
5
class InputSlider extends InputGroupComponent
6
{
7
    /**
8
     * The bootstrap-slider plugin configuration parameters. Array with
9
     * key => value pairs, where the key should be an existing configuration
10
     * property of the plugin.
11
     *
12
     * @var array
13
     */
14
    public $config;
15
16
    /**
17
     * The slider color. One of the available html colors.
18
     *
19
     * @var string
20
     */
21
    public $color;
22
23
    /**
24
     * Create a new component instance.
25
     * Note this component requires the 'bootstrap-slider' plugin.
26
     *
27
     * @return void
28
     */
29 1
    public function __construct(
30
        $name, $label = null, $size = null, $labelClass = null,
31
        $topClass = null, $disableFeedback = null, $config = [], $color = null
32
    ) {
33 1
        parent::__construct(
34 1
            $name, $label, $size, $labelClass, $topClass, $disableFeedback
35
        );
36
37 1
        $this->config = is_array($config) ? $config : [];
38 1
        $this->color = $color;
39
40
        // Set a default plugin 'id' option.
41
42 1
        $this->config['id'] = $this->config['id'] ?? "{$name}-slider";
43 1
    }
44
45
    /**
46
     * Get the view / contents that represent the component.
47
     *
48
     * @return \Illuminate\View\View|string
49
     */
50 1
    public function render()
51
    {
52 1
        return view('adminlte::components.input-slider');
53
    }
54
}
55