Textarea::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 26

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 26
rs 9.504
c 0
b 0
f 0
cc 2
nc 2
nop 11

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 Textarea extends Component
9
{
10
    public $type;
11
    public $name;
12
    public $placeholder;
13
    public $label;
14
    public $cols;
15
    public $rows;
16
    public $value;
17
    public $class;
18
    public $readonly;
19
    public $required;
20
    public $icon;
21
22
    public function __construct(
23
        $type = 'text',
24
        $name = null,
25
        $placeholder = null,
26
        $label = null,
27
        $cols = null,
28
        $rows = null,
29
        $value = null,
30
        $class = null,
31
        $readonly = null,
32
        $required = false,
33
        $icon = null
34
    )
35
    {
36
        $this->type = $type;
37
        $this->name = $name ?? str_replace('-', '_', Str::kebab($label));
38
        $this->placeholder = $placeholder ?? (!$name ? str_replace('-', '_', Str::kebab($label)) : '');
39
        $this->label = $label;
40
        $this->cols = $cols;
41
        $this->rows = $rows;
42
        $this->value = old($this->name, ($value ?? ''));
43
        $this->class = $class;
44
        $this->readonly = $readonly;
45
        $this->required = $required;
46
        $this->icon = $icon;
47
    }
48
49
50
    public function render()
51
    {
52
        return view('template::lte.components._fields.textarea');
53
    }
54
}
55