ToastComponent::updatedProd()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usernotnull\Toast\Http\Livewire;
6
7
use Illuminate\Contracts\Foundation\Application;
8
use Illuminate\Contracts\View\Factory;
9
use Illuminate\Contracts\View\Factory as ViewFactory;
10
use Illuminate\Contracts\View\View;
11
use Illuminate\Support\Facades\App;
12
use Livewire\Component;
13
use Usernotnull\Toast\ToastManager;
14
15
class ToastComponent extends Component
16
{
17
    public int $duration;
18
19
    public int $loadDelay;
20
21
    public bool $prod;
22
23
    public array $toasts = [];
24
25
    public function dehydrate(): void
26
    {
27
        ToastManager::setComponentRendered(true);
28
29
        $this->toasts = array_merge($this->toasts, ToastManager::pull());
30
    }
31
32
    public function mount(): void
33
    {
34
        if (session()->has(config('tall-toasts.session_keys.toasts_next_page'))) {
35
            $this->toasts = ToastManager::pullNextPage();
36
        }
37
38
        $this->duration = config('tall-toasts.duration');
39
40
        $this->loadDelay = config('tall-toasts.load_delay');
41
42
        $this->prod = App::isProduction();
43
    }
44
45
    public function render(): View|Factory|Application
46
    {
47
        return app(ViewFactory::class)->make('tall-toasts::livewire.toasts');
48
    }
49
50
    public function updatedProd(): void
51
    {
52
        $this->prod = App::isProduction();
53
    }
54
}
55