Passed
Pull Request — 2.x (#1360)
by Harings
14:11
created

Checkboxes::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 45
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 21
c 1
b 0
f 0
nc 1
nop 20
dl 0
loc 45
rs 9.584

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 A17\Twill\View\Components;
4
5
class Checkboxes extends FieldWithOptions
6
{
7
    public $inline;
8
    public $border;
9
    public $min;
10
    public $max;
11
12
    public function __construct(
13
        $name,
14
        $label,
15
        $renderForBlocks = false,
16
        $renderForModal = false,
17
        $options = [],
18
        $unpack = false,
19
        $columns = 0,
20
        $searchable = false,
21
        $note = null,
22
        $placeholder = null,
23
        $disabled = false,
24
        $addNew = false,
25
        $moduleName = null,
26
        $storeUrl = null,
27
        $fieldsInModal = false,
28
        $default = false,
29
        $min = null,
30
        $max = null,
31
        $inline = false,
32
        $border = false
33
    ) {
34
        parent::__construct(
35
            $name,
36
            $label,
37
            $renderForBlocks,
38
            $renderForModal,
39
            $options,
40
            $unpack,
41
            $columns,
42
            $searchable,
43
            $note,
44
            $placeholder,
45
            $disabled,
46
            $addNew,
47
            $moduleName,
48
            $storeUrl,
49
            $default,
50
            $fieldsInModal
51
        );
52
53
        $this->inline = $inline;
54
        $this->border = $border;
55
        $this->min = $min;
56
        $this->max = $max;
57
    }
58
59
    public function render()
60
    {
61
        return view('twill::partials.form._checkboxes', [
62
            'options' => $this->options,
63
            'inModal' => $this->isInModal()
64
        ]);
65
    }
66
}
67