Toast   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 7
c 2
b 0
f 0
dl 0
loc 29
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A warning() 0 3 1
A info() 0 3 1
A danger() 0 3 1
A debug() 0 7 2
A success() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Usernotnull\Toast;
6
7
use function is_string;
8
9
class Toast
10
{
11
    public function danger(string $message, string $title = null): Notification
12
    {
13
        return new Notification($message, $title, NotificationType::$danger);
14
    }
15
16
    public function debug(mixed $message, string $title = null): Notification
17
    {
18
        if (! is_string($message)) {
19
            $message = json_encode($message, JSON_THROW_ON_ERROR | JSON_PRETTY_PRINT);
20
        }
21
22
        return new Notification($message, $title, NotificationType::$debug);
23
    }
24
25
    public function info(string $message, string $title = null): Notification
26
    {
27
        return new Notification($message, $title, NotificationType::$info);
28
    }
29
30
    public function success(string $message, string $title = null): Notification
31
    {
32
        return new Notification($message, $title, NotificationType::$success);
33
    }
34
35
    public function warning(string $message, string $title = null): Notification
36
    {
37
        return new Notification($message, $title, NotificationType::$warning);
38
    }
39
}
40