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

Input::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 36
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 17
dl 0
loc 36
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
    ) {
42
        parent::__construct($name, $label);
43
44
        $this->type = $type;
45
        $this->translated = $translated;
46
        $this->required = $required;
47
        $this->note = $note;
48
        $this->placeholder = $placeholder;
49
        $this->maxlength = $maxlength;
50
        $this->disabled = $disabled;
51
        $this->readonly = $readonly;
52
        $this->default = $default;
53
        $this->rows = $rows;
54
        $this->ref = $ref;
55
        $this->onChange = $onChange;
56
        $this->onChangeAttribute = $onChangeAttribute;
57
        $this->prefix = $prefix;
58
        $this->inModal = $inModal;
59
    }
60
61
    public function render()
62
    {
63
        return view('twill::partials.form._input', [
64
            'onChangeFullAttribute' => $this->onChangeAttribute ? "('".$this->onChangeAttribute."', ...arguments)" : "",
65
        ]);
66
    }
67
}
68