Passed
Push — 5.0.0 ( 746f48...fc989a )
by Fèvre
06:29
created

ListItem::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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

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 Xetaravel\View\Components;
4
5
use Closure;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\View\Component;
8
9
class ListItem extends Component
10
{
11
    public string $uuid;
12
13
    public function __construct(
14
        public object|array $item,
15
        public string $avatar = 'avatar',
16
        public string $value = 'name',
17
        public ?string $subValue = '',
18
        public ?bool $noSeparator = false,
19
        public ?bool $noHover = false,
20
        public ?string $link = null,
21
22
        // Slots
23
        public mixed $actions = null,
24
    ) {
25
        $this->uuid = md5(serialize($this));
26
    }
27
28
    /**
29
     * Get the view / contents that represent the component.
30
     */
31
    public function render(): View|Closure|string
32
    {
33
        return view('components.list-item');
34
    }
35
}
36