Input::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 22
rs 9.568
c 0
b 0
f 0
cc 2
nc 2
nop 9

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 Aminetiyal\LaravelTemplate\Components\Lte\Field;
4
5
use Illuminate\View\Component;
6
use Illuminate\Support\Str;
7
8
class Input extends Component
9
{
10
    public $type;
11
    public $name;
12
    public $placeholder;
13
    public $label;
14
    public $value;
15
    public $class;
16
    public $readonly;
17
    public $required;
18
    public $checked;
19
    public $icon;
20
21
    public function __construct(
22
        $type = 'text',
23
        $name = null,
24
        $placeholder = null,
25
        $label = null,
26
        $value = null,
27
        $class = null,
28
        $readonly = null,
29
        $required = false,
30
        $icon = null
31
    )
32
    {
33
        $this->type = $type;
34
        $this->name = $name ?? str_replace('-', '_', Str::kebab($label));
35
        $this->placeholder = $placeholder ?? (!$name ? str_replace('-', '_', Str::kebab($label)) : '');
36
        $this->label = $label;
37
        $this->value = old($this->name, ($value ?? ''));
38
        $this->class = $class;
39
        $this->readonly = $readonly;
40
        $this->required = $required;
41
        $this->icon = $icon;
42
    }
43
44
    public function render()
45
    {
46
        return view('template::lte.components._fields.input');
47
    }
48
}
49