Completed
Push — master ( 3e6638...212062 )
by Pascal
16s queued 14s
created

Component   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A id() 0 7 2
A isNotWired() 0 3 1
A render() 0 9 1
A isWired() 0 3 1
1
<?php
2
3
namespace ProtoneMedia\LaravelFormComponents\Components;
4
5
use Illuminate\Support\Str;
6
use Illuminate\View\Component as BaseComponent;
7
use ProtoneMedia\LaravelFormComponents\FormDataBinder;
8
9
abstract class Component extends BaseComponent
10
{
11
    /**
12
     * ID for this component.
13
     *
14
     * @var string
15
     */
16
    private $id;
17
18
    /**
19
     * {@inheritDoc}
20
     */
21
    public function render()
22
    {
23
        $alias = Str::kebab(class_basename($this));
24
25
        $config = config("form-components.components.{$alias}");
26
27
        $framework = config("form-components.framework");
28
29
        return str_replace('{framework}', $framework, $config['view']);
30
    }
31
32
    /**
33
     * Returns a boolean wether the form is wired to a Livewire component.
34
     *
35
     * @return boolean
36
     */
37
    public function isWired(): bool
38
    {
39
        return app(FormDataBinder::class)->isWired();
40
    }
41
42
    /**
43
     * The inversion of 'isWired()'.
44
     *
45
     * @return boolean
46
     */
47
    public function isNotWired(): bool
48
    {
49
        return !$this->isWired();
50
    }
51
52
    /**
53
     * Generates an ID, once, for this component.
54
     *
55
     * @return string
56
     */
57
    public function id(): string
58
    {
59
        if (!$this->id) {
60
            $this->id = Str::random(4);
61
        }
62
63
        return $this->id;
64
    }
65
}
66