microsoftTeamsRespondedWithAnError()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
dl 0
loc 11
ccs 0
cts 6
cp 0
rs 9.9
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 6
1
<?php
2
3
namespace NotificationChannels\MicrosoftTeams\Exceptions;
4
5
use GuzzleHttp\Exception\ClientException;
6
7
class CouldNotSendNotification extends \Exception
8
{
9
    /**
10
     * Thrown when there's a bad request and an error is responded.
11
     *
12
     * @param ClientException $exception
13
     *
14
     * @return static
15
     */
16
    public static function microsoftTeamsRespondedWithAnError(ClientException $exception)
17
    {
18
        if (! $exception->hasResponse()) {
19
            return new static('Microsoft Teams responded with an error but no response body found');
20
        }
21
22
        $statusCode = $exception->getResponse()->getStatusCode();
23
        $description = $exception->getMessage();
24
25
        return new static("Microsoft Teams responded with an error `{$statusCode} - {$description}`");
26
    }
27
28
    /**
29
     * Thrown when we're unable to communicate with Microsoft Teams.
30
     *
31
     * @param \Exception $exception
32
     *
33
     * @return static
34
     */
35
    public static function couldNotCommunicateWithMicrosoftTeams(\Exception $exception)
36
    {
37
        return new static("The communication with Microsoft Teams failed. `{$exception->getMessage()}`");
38
    }
39
40
    /**
41
     * Thrown when there is no webhook url provided.
42
     *
43
     * @return static
44
     */
45 2
    public static function microsoftTeamsWebhookUrlMissing()
46
    {
47 2
        return new static('Microsoft Teams webhook url is missing. Please add it as param over the MicrosoftTeamsMessage::to($url) method or return it in the notifiable model by providing the method Model::routeNotificationForMicrosoftTeams().');
48
    }
49
}
50