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

Input::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 16
c 1
b 0
f 0
nc 1
nop 19
dl 0
loc 38
rs 9.7333

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 Input extends TwillFormComponent
6
{
7
    public $type;
8
    public $translated;
9
    public $required;
10
    public $placeholder;
11
    public $maxlength;
12
    public $readonly;
13
    public $rows;
14
    public $ref;
15
    public $onChange;
16
    public $onChangeAttribute;
17
    public $prefix;
18
    public $inModal;
19
    public $note;
20
    public $disabled;
21
    public $default;
22
23
    public function __construct(
24
        $name,
25
        $label,
26
        $type = 'text',
27
        $translated = false,
28
        $required = false,
29
        $note = null,
30
        $placeholder = null,
31
        $maxlength = null,
32
        $disabled = false,
33
        $readonly = false,
34
        $default = null,
35
        $rows = null,
36
        $ref = null,
37
        $onChange = null,
38
        $onChangeAttribute = null,
39
        $prefix = null,
40
        $inModal = false,
41
        $renderForBlocks = false,
42
        $renderForModal = false
43
    ) {
44
        parent::__construct($name, $label, $renderForBlocks, $renderForModal);
45
46
        $this->type = $type;
47
        $this->translated = $translated;
48
        $this->required = $required;
49
        $this->note = $note;
50
        $this->placeholder = $placeholder;
51
        $this->maxlength = $maxlength;
52
        $this->disabled = $disabled;
53
        $this->readonly = $readonly;
54
        $this->default = $default;
55
        $this->rows = $rows;
56
        $this->ref = $ref;
57
        $this->onChange = $onChange;
58
        $this->onChangeAttribute = $onChangeAttribute;
59
        $this->prefix = $prefix;
60
        $this->inModal = $inModal;
61
    }
62
63
    public function render()
64
    {
65
        return view('twill::partials.form._input', [
66
            'onChangeFullAttribute' => $this->onChangeAttribute ? "('".$this->onChangeAttribute."', ...arguments)" : "",
67
        ]);
68
    }
69
}
70