CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 46
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A hooksRespondedWithAnError() 0 7 1
A hooksApiKeyNotProvided() 0 4 1
A couldNotCommunicateWithHooks() 0 4 1
A alertIdNotProvided() 0 4 1
1
<?php
2
3
namespace NotificationChannels\Hooks\Exceptions;
4
5
use Exception;
6
use GuzzleHttp\Exception\ClientException;
7
8
class CouldNotSendNotification extends \Exception
9
{
10
    /**
11
     * Thrown when there's a bad request and an error is responded.
12
     *
13
     * @param ClientException $exception
14
     *
15
     * @return static
16
     */
17
    public static function hooksRespondedWithAnError(ClientException $exception)
18
    {
19
        $statusCode = $exception->getResponse()->getStatusCode();
20
        $result = json_decode($exception->getResponse()->getBody());
21
22
        return new static("Hooks API responded with an error `{$statusCode} - {$result->status} : {$result->msg}`");
23
    }
24
25
    /**
26
     * Thrown when there's no api key provided.
27
     *
28
     * @param string $message
29
     *
30
     * @return static
31
     */
32
    public static function hooksApiKeyNotProvided($message)
33
    {
34
        return new static($message);
35
    }
36
37
    /**
38
     * Thrown when we're unable to communicate with Hooks API.
39
     *
40
     * @param \Exception $exception
41
     *
42
     * @return static
43
     */
44
    public static function couldNotCommunicateWithHooks(Exception $exception)
45
    {
46
        return new static('The communication with Hooks API failed. Reason: '.$exception->getMessage());
47
    }
48
49
    public static function alertIdNotProvided()
50
    {
51
        return new static('Alert ID for this notification was not provided.');
52
    }
53
}
54