Passed
Push — 5.0.0 ( 47cf5a...33d584 )
by Fèvre
07:06
created

Checkbox::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 9
dl 0
loc 14
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 Checkbox extends Component
10
{
11
    public string $uuid;
12
13
    public function __construct(
14
        public ?string $id = null,
15
        public ?string $label = null,
16
        public ?bool $right = false,
17
        public ?string $hint = null,
18
        public ?string $hintClass = 'fieldset-label',
19
20
        // Validations
21
        public ?string $errorField = null,
22
        public ?string $errorClass = 'text-error',
23
        public ?bool $omitError = false,
24
        public ?bool $firstErrorOnly = false,
25
    ) {
26
        $this->uuid = md5(serialize($this)) . $id;
27
    }
28
29
    public function modelName(): ?string
30
    {
31
        return $this->attributes->whereStartsWith('wire:model')->first();
32
    }
33
34
    public function errorFieldName(): ?string
35
    {
36
        return $this->errorField ?? $this->modelName();
37
    }
38
39
    /**
40
     * Get the view / contents that represent the component.
41
     */
42
    public function render(): View|Closure|string
43
    {
44
        return view('components.checkbox');
45
    }
46
}
47