CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 50%

Importance

Changes 0
Metric Value
dl 0
loc 52
ccs 7
cts 14
cp 0.5
rs 10
c 0
b 0
f 0
wmc 5
lcom 1
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hipChatRespondedWithAnError() 0 8 1
A missingTo() 0 4 1
A invalidMessageObject() 0 8 2
A internalError() 0 4 1
1
<?php
2
3
namespace NotificationChannels\HipChat\Exceptions;
4
5
use Exception;
6
use GuzzleHttp\Exception\ClientException;
7
use NotificationChannels\HipChat\HipChatMessage;
8
9
class CouldNotSendNotification extends Exception
10
{
11
    /**
12
     * Thrown when there's a bad request from the HttpClient.
13
     *
14
     * @param \GuzzleHttp\Exception\ClientException $exception
15
     * @return static
16
     */
17
    public static function hipChatRespondedWithAnError(ClientException $exception)
18
    {
19
        return new static(sprintf(
20
            'HipChat responded with an error %s - %s',
21
            $exception->getResponse()->getStatusCode(),
22
            $exception->getResponse()->getBody()
23
        ));
24
    }
25
26
    /**
27
     * Thrown when to (room identifier) is missing.
28
     *
29
     * @return static
30
     */
31 1
    public static function missingTo()
32
    {
33 1
        return new static('Notification was not sent. Room identifier is missing.');
34
    }
35
36
    /**
37
     * Thrown when an invalid message object was passed.
38
     *
39
     * @param mixed $message
40
     * @return static
41
     */
42 1
    public static function invalidMessageObject($message)
43
    {
44 1
        return new static(sprintf(
45 1
            'Notification was not sent. The message should be an instance of or extend %s. Given % is invalid.',
46 1
            HipChatMessage::class,
47 1
            get_class($message) ?: 'Unknown'
48
        ));
49
    }
50
51
    /**
52
     * Thrown when any other exception is caught while sending a notification message.
53
     *
54
     * @return static
55
     */
56
    public static function internalError($exception = null)
57
    {
58
        return new static('Error occurred while sending the message.', 0, $exception);
59
    }
60
}
61