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

Icon   A

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
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