Completed
Push — master ( e5e129...73cdcc )
by Vaibhavraj
01:47
created

CouldNotSendNotification::flockMessageException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 0
cts 2
cp 0
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 2
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