CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 120
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 7.69%

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 0
dl 0
loc 120
ccs 2
cts 26
cp 0.0769
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A serviceRespondedWithAnError() 0 4 1
A flockRespondedWithAnError() 0 10 3
A flockRouteNotProvided() 0 4 1
A flockAttachmentViewWidgetException() 0 4 1
A flockAttachmentViewHtmlException() 0 4 1
A flockAttachmentViewImageException() 0 4 1
A flockAttachmentUrlException() 0 4 1
A flockAttachmentForwardException() 0 4 1
A flockAttachmentDownloadException() 0 4 1
A flockAttachmentButtonException() 0 4 1
A flockMessageException() 0 4 1
1
<?php
2
3
namespace NotificationChannels\Flock\Exceptions;
4
5
use GuzzleHttp\Exception\ClientException;
6
7
class CouldNotSendNotification extends \Exception
8
{
9
    /**
10
     * Generic method to show the exception.
11
     *
12
     * @return static
13
     */
14
    public static function serviceRespondedWithAnError()
15
    {
16
        return new static('Descriptive error message.');
17
    }
18
19
    /**
20
     * Thrown when there's a bad request and an error is responded.
21
     *
22
     * @param ClientException $exception
23
     *
24
     * @return static
25
     */
26
    public static function flockRespondedWithAnError(ClientException $exception)
27
    {
28
        $statusCode = $exception->getResponse()->getStatusCode();
29
        $description = 'no description given';
30
        if ($result = json_decode($exception->getResponse()->getBody())) {
31
            $description = $result->description ?: $description;
32
        }
33
34
        return new static("Flock responded with an error `{$statusCode} - {$description}`. Check your notification fields.");
35
    }
36
37
    /**
38
     * Thrown when there is no Incoming webhook url provided.
39
     *
40
     * @return static
41
     */
42 1
    public static function flockRouteNotProvided()
43
    {
44 1
        return new static('Flock incoming webhook url not provided.');
45
    }
46
47
    /**
48
     * Thrown when attachment views widget source, height, width is not provided or invalid.
49
     *
50
     * @return static
51
     */
52
    public static function flockAttachmentViewWidgetException($exception)
53
    {
54
        return new static($exception);
55
    }
56
57
    /**
58
     * Thrown when attachment views inline html source, height, width is not provided or invalid.
59
     *
60
     * @return static
61
     */
62
    public static function flockAttachmentViewHtmlException($exception)
63
    {
64
        return new static($exception);
65
    }
66
67
    /**
68
     * Thrown when attachment views image source, height, width is not provided or invalid.
69
     *
70
     * @return static
71
     */
72
    public static function flockAttachmentViewImageException($exception)
73
    {
74
        return new static($exception);
75
    }
76
77
    /**
78
     * Thrown when attachment URL field not provided or invalid.
79
     *
80
     * @return static
81
     */
82
    public static function flockAttachmentUrlException($exception)
83
    {
84
        return new static($exception);
85
    }
86
87
    /**
88
     * Thrown when attachment forward field is non boolean.
89
     *
90
     * @return static
91
     */
92
    public static function flockAttachmentForwardException($exception)
93
    {
94
        return new static($exception);
95
    }
96
97
    /**
98
     * Thrown when attachment download field source is invalid or missing.
99
     *
100
     * @return static
101
     */
102
    public static function flockAttachmentDownloadException($exception)
103
    {
104
        return new static($exception);
105
    }
106
107
    /**
108
     * Thrown when attachment button field has an error.
109
     *
110
     * @return static
111
     */
112
    public static function flockAttachmentButtonException($exception)
113
    {
114
        return new static($exception);
115
    }
116
117
    /**
118
     * Thrown when message object has invaild values.
119
     *
120
     * @return static
121
     */
122
    public static function flockMessageException($exception)
123
    {
124
        return new static($exception);
125
    }
126
}
127