CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
eloc 6
dl 0
loc 29
ccs 7
cts 7
cp 1
rs 10
c 2
b 1
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sendingFailed() 0 7 2
A invalidMessage() 0 5 2
1
<?php
2
3
namespace NotificationChannels\BearyChat\Exceptions;
4
5
use ElfSundae\BearyChat\Message;
6
use Exception;
7
8
class CouldNotSendNotification extends Exception
9
{
10
    /**
11
     * Thrown when an invalid message was passed.
12
     *
13
     * @param  mixed  $message
14
     * @return static
15
     */
16 4
    public static function invalidMessage($message)
17
    {
18 4
        $type = is_object($message) ? get_class($message) : gettype($message);
19
20 4
        return new static('The message should be an instance of '.Message::class.". Given `{$type}` is invalid.", 1);
21
    }
22
23
    /**
24
     * Thrown when sending failed.
25
     *
26
     * @param  string  $webhook
27
     * @param  mixed  $payload
28
     * @return static
29
     */
30 4
    public static function sendingFailed($webhook, $payload)
31
    {
32 4
        if (! is_string($payload)) {
33 4
            $payload = json_encode($payload, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
34
        }
35
36 4
        return new static("Failed sending to BearyChat with webhook {$webhook} .\n{$payload}", 4);
37
    }
38
}
39