Passed
Push — main ( d45bb9...aef137 )
by John
03:56 queued 12s
created

Notification::pushOnNextPage()   A

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;
6
7
class Notification
8
{
9
    public function __construct(
10
        protected string $message,
11
        protected ?string $title,
12
        protected ?string $type = null
13
    ) {
14
        $this->message = htmlspecialchars($message, ENT_QUOTES);
15
        $this->title = $title ? htmlspecialchars($title, ENT_QUOTES) : '';
16
        $this->type = $type ?? NotificationType::$info;
17
    }
18
19
    protected function asArray(): array
20
    {
21
        return [
22
            'message' => $this->message,
23
            'title' => $this->title ?? '',
24
            'type' => $this->type,
25
        ];
26
    }
27
28
    public static function make(
29
        string $message,
30
        ?string $title,
31
        ?string $type = null
32
    ): array {
33
        return (new static($message, $title, $type))->asArray();
34
    }
35
36
    public function push(): void
37
    {
38
        session()->push(config('tall-toasts.session_keys.toasts'), $this->asArray());
39
    }
40
41
    public function pushOnNextPage(): void
42
    {
43
        session()->push(config('tall-toasts.session_keys.toasts_next_page'), $this->asArray());
44
    }
45
}
46