| Total Complexity | 9 |
| Total Lines | 53 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 7 | class Notification |
||
| 8 | { |
||
| 9 | protected bool $sanitize; |
||
| 10 | |||
| 11 | protected string $message; |
||
| 12 | |||
| 13 | protected ?string $title; |
||
| 14 | |||
| 15 | protected ?string $type; |
||
| 16 | |||
| 17 | public function __construct( |
||
| 18 | string $message, |
||
| 19 | ?string $title, |
||
| 20 | ?string $type = null |
||
| 21 | ) { |
||
| 22 | $this->type = $type; |
||
| 23 | $this->title = $title; |
||
| 24 | $this->message = $message; |
||
| 25 | $this->sanitize = $type !== NotificationType::$debug; |
||
| 26 | } |
||
| 27 | |||
| 28 | protected function asArray(): array |
||
| 29 | { |
||
| 30 | $message = $this->sanitize ? htmlspecialchars($this->message, ENT_QUOTES) : $this->message; |
||
| 31 | $title = $this->sanitize && $this->title ? htmlspecialchars($this->title, ENT_QUOTES) : $this->title; |
||
| 32 | $type = $this->type ?? NotificationType::$info; |
||
| 33 | |||
| 34 | return compact('message', 'title', 'type'); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function doNotSanitize(): Notification |
||
| 42 | } |
||
| 43 | |||
| 44 | public static function make( |
||
| 45 | string $message, |
||
| 46 | ?string $title, |
||
| 47 | ?string $type = null |
||
| 48 | ): array { |
||
| 49 | return (new static($message, $title, $type))->asArray(); |
||
| 50 | } |
||
| 51 | |||
| 52 | public function push(): void |
||
| 53 | { |
||
| 54 | session()->push(config('tall-toasts.session_keys.toasts'), $this->asArray()); |
||
| 55 | } |
||
| 56 | |||
| 57 | public function pushOnNextPage(): void |
||
| 60 | } |
||
| 61 | } |
||
| 62 |