CouldNotSendNotification::missingFrom()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace NotificationChannels\Gitter\Exceptions;
4
5
use Exception;
6
use GuzzleHttp\Exception\ClientException;
7
8
class CouldNotSendNotification extends Exception
9
{
10
    /**
11
     * Thrown when room identifier is missing.
12
     *
13
     * @return static
14
     */
15 1
    public static function missingRoom()
16
    {
17 1
        return new static('Notification was not sent. Room identifier is missing.');
18
    }
19
20
    /**
21
     * Thrown when user or app access token is missing.
22
     *
23
     * @return static
24
     */
25 1
    public static function missingFrom()
26
    {
27 1
        return new static('Notification was not sent. Access token is missing.');
28
    }
29
30
    /**
31
     * Thrown when there's a bad response from the Gitter.
32
     *
33
     * @param ClientException $exception
34
     *
35
     * @return static
36
     */
37
    public static function gitterRespondedWithAnError(ClientException $exception)
38
    {
39
        $message = $exception->getResponse()->getBody();
40
        $code = $exception->getResponse()->getStatusCode();
41
42
        return new static("Gitter responded with an error `{$code} - {$message}`");
43
    }
44
45
    /**
46
     * Thrown when we're unable to communicate with Gitter.
47
     *
48
     * @param  Exception  $exception
49
     *
50
     * @return static
51
     */
52
    public static function couldNotCommunicateWithGitter(Exception $exception)
53
    {
54
        return new static("The communication with Gitter failed. Reason: {$exception->getMessage()}");
55
    }
56
}
57