Completed
Push — master ( 64671b...d6e3c8 )
by
unknown
23s queued 11s
created

CouldNotSendNotification   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 60%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 47
ccs 6
cts 10
cp 0.6
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A missingTo() 0 4 1
A missingFrom() 0 4 1
A rocketChatRespondedWithAnError() 0 7 1
A couldNotCommunicateWithRocketChat() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace NotificationChannels\RocketChat\Exceptions;
6
7
use Exception;
8
use GuzzleHttp\Exception\ClientException;
9
use RuntimeException;
10
11
final class CouldNotSendNotification extends RuntimeException
12
{
13
    /**
14
     * Thrown when channel identifier is missing.
15
     *
16
     * @return static
17
     */
18 1
    public static function missingTo(): self
19
    {
20 1
        return new static('Notification was not sent. Channel identifier is missing.');
21
    }
22
23
    /**
24
     * Thrown when user or app access token is missing.
25
     *
26
     * @return static
27
     */
28 1
    public static function missingFrom(): self
29
    {
30 1
        return new static('Notification was not sent. Access token is missing.');
31
    }
32
33
    /**
34
     * Thrown when there's a bad response from the RocketChat.
35
     *
36
     * @param  \GuzzleHttp\Exception\ClientException  $exception
37
     * @return static
38
     */
39
    public static function rocketChatRespondedWithAnError(ClientException $exception): self
40
    {
41
        $message = $exception->getResponse()->getBody();
42
        $code = $exception->getResponse()->getStatusCode();
43
44
        return new static("RocketChat responded with an error `{$code} - {$message}`");
45
    }
46
47
    /**
48
     * Thrown when we're unable to communicate with RocketChat.
49
     *
50
     * @param  \Exception  $exception
51
     * @return static
52
     */
53 1
    public static function couldNotCommunicateWithRocketChat(Exception $exception): self
54
    {
55 1
        return new static("The communication with RocketChat failed. Reason: {$exception->getMessage()}");
56
    }
57
}
58