CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 40%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 49
ccs 4
cts 10
cp 0.4
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A missingRoom() 0 4 1
A missingFrom() 0 4 1
A gitterRespondedWithAnError() 0 7 1
A couldNotCommunicateWithGitter() 0 4 1
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