ToastComponent   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 3 1
A updatedProd() 0 3 1
A mount() 0 11 2
A dehydrate() 0 5 1
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