Passed
Push — 5.0.0 ( ae03fe...9fcb89 )
by Fèvre
05:56
created

Icon::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 2
dl 0
loc 5
rs 10
1
<?php
2
3
namespace Xetaravel\View\Components;
4
5
use Closure;
6
use Illuminate\Contracts\View\View;
7
use Illuminate\Support\Str;
8
use Illuminate\Support\Stringable;
9
use Illuminate\View\Component;
10
11
class Icon extends Component
12
{
13
    public string $uuid;
14
15
    public function __construct(
16
        public string $name,
17
        public ?string $label = null
18
    ) {
19
        $this->uuid = md5(serialize($this));
20
    }
21
22
    public function icon(): string|Stringable
23
    {
24
        $name = Str::of($this->name);
25
26
        return $name->contains('.') ? $name->replace('.', '-') : "heroicon-{$this->name}";
27
    }
28
29
    public function labelClasses(): ?string
30
    {
31
        // Remove `w-*` and `h-*` classes, because it applies only for icon
32
        return Str::replaceMatches('/(w-\w*)|(h-\w*)/', '', $this->attributes->get('class') ?? '');
33
    }
34
35
    /**
36
     * Get the view / contents that represent the component.
37
     */
38
    public function render(): View|Closure|string
39
    {
40
        return view('components.icon');
41
    }
42
}
43