CouldNotSendNotification::sendingFailed()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 2
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
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