FormInput::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 21
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 21
rs 10
cc 3
nc 4
nop 8

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 ProtoneMedia\LaravelFormComponents\Components;
4
5
class FormInput extends Component
6
{
7
    use HandlesValidationErrors;
8
    use HandlesDefaultAndOldValue;
9
10
    public string $name;
11
    public string $label;
12
    public string $type;
13
    public bool $floating;
14
15
    public $value;
16
17
    /**
18
     * Create a new component instance.
19
     *
20
     * @return void
21
     */
22
    public function __construct(
23
        string $name,
24
        string $label = '',
25
        string $type = 'text',
26
        $bind = null,
27
        $default = null,
28
        $language = null,
29
        bool $showErrors = true,
30
        bool $floating = false
31
    ) {
32
        $this->name       = $name;
33
        $this->label      = $label;
34
        $this->type       = $type;
35
        $this->showErrors = $showErrors;
36
        $this->floating   = $floating && $type !== 'hidden';
37
38
        if ($language) {
39
            $this->name = "{$name}[{$language}]";
40
        }
41
42
        $this->setValue($name, $bind, $default, $language);
43
    }
44
}
45