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

Checkbox   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 36
rs 10
c 1
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A modelName() 0 3 1
A render() 0 3 1
A errorFieldName() 0 3 1
A __construct() 0 14 1
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