Tab::jsonSerialize()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Facade\Ignition\Tabs;
4
5
use Facade\FlareClient\Flare;
6
use Illuminate\Support\Str;
7
use JsonSerializable;
8
use Throwable;
9
10
abstract class Tab implements JsonSerializable
11
{
12
    public $scripts = [];
13
14
    public $styles = [];
15
16
    /** @var \Facade\Ignition\Facades\Flare */
17
    protected $flare;
18
19
    /** @var Throwable */
20
    protected $throwable;
21
22
    public function __construct()
23
    {
24
        $this->registerAssets();
25
    }
26
27
    public function name(): string
28
    {
29
        return Str::studly(class_basename(get_called_class()));
30
    }
31
32
    public function component(): string
33
    {
34
        return Str::snake(class_basename(get_called_class()), '-');
35
    }
36
37
    public function beforeRenderingErrorPage(Flare $flare, Throwable $throwable)
38
    {
39
        $this->flare = $flare;
0 ignored issues
show
Documentation Bug introduced by
It seems like $flare of type object<Facade\FlareClient\Flare> is incompatible with the declared type object<Facade\Ignition\Facades\Flare> of property $flare.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
41
        $this->throwable = $throwable;
42
    }
43
44
    public function script(string $name, string $path)
45
    {
46
        $this->scripts[$name] = $path;
47
48
        return $this;
49
    }
50
51
    public function style(string $name, string $path)
52
    {
53
        $this->styles[$name] = $path;
54
55
        return $this;
56
    }
57
58
    abstract protected function registerAssets();
59
60
    public function meta(): array
61
    {
62
        return [];
63
    }
64
65
    public function jsonSerialize()
66
    {
67
        return [
68
            'title' => $this->name(),
69
            'component' => $this->component(),
70
            'props' => [
71
                'meta' => $this->meta(),
72
            ],
73
        ];
74
    }
75
}
76