Passed
Push — 5.0.0 ( 9fcb89...47cf5a )
by Fèvre
05:30
created

Button::__construct()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 19
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

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

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 Button extends Component
10
{
11
    public string $uuid;
12
13
    public string $tooltipPosition = 'lg:tooltip-top';
14
15
    public function __construct(
16
        public ?string $label = null,
17
        public ?string $icon = null,
18
        public ?string $iconRight = null,
19
        public ?string $spinner = null,
20
        public ?string $link = null,
21
        public ?bool $external = false,
22
        public ?bool $noWireNavigate = false,
23
        public ?bool $responsive = false,
24
        public ?string $badge = null,
25
        public ?string $badgeClasses = null,
26
        public ?string $tooltip = null,
27
        public ?string $tooltipLeft = null,
28
        public ?string $tooltipRight = null,
29
        public ?string $tooltipBottom = null,
30
    ) {
31
        $this->uuid = md5(serialize($this));
32
        $this->tooltip = $this->tooltip ?? $this->tooltipLeft ?? $this->tooltipRight ?? $this->tooltipBottom;
33
        $this->tooltipPosition = $this->tooltipLeft ? 'lg:tooltip-left' : ($this->tooltipRight ? 'lg:tooltip-right' : ($this->tooltipBottom ? 'lg:tooltip-bottom' : 'lg:tooltip-top'));
34
    }
35
36
    public function spinnerTarget(): ?string
37
    {
38
        if ($this->spinner == 1) {
39
            return $this->attributes->whereStartsWith('wire:click')->first();
40
        }
41
42
        return $this->spinner;
43
    }
44
45
    /**
46
     * Get the view / contents that represent the component.
47
     */
48
    public function render(): View|Closure|string
49
    {
50
        return view('components.button');
51
    }
52
}
53