Icon   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 30
rs 10
wmc 5

4 Methods

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