GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 97e8d1...15f2c9 )
by Cody
02:35
created

CouldNotSendNotification   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 2
dl 0
loc 38
ccs 0
cts 16
cp 0
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A serviceRespondedWithAnHttpError() 0 10 2
A serviceRespondedWithAnApiError() 0 4 1
A serviceCommunicationError() 0 4 1
1
<?php
2
3
namespace NotificationChannels\Discord\Exceptions;
4
5
use Exception;
6
use Illuminate\Support\Arr;
7
use Psr\Http\Message\ResponseInterface;
8
9
class CouldNotSendNotification extends Exception
10
{
11
    /**
12
     * @param \Psr\Http\Message\ResponseInterface $response
13
     *
14
     * @return static
15
     */
16
    public static function serviceRespondedWithAnHttpError(ResponseInterface $response)
17
    {
18
        $message = "Discord responded with an HTTP error: {$response->getStatusCode()}";
19
20
        if ($error = Arr::get(json_decode($response->getBody(), true), 'message')) {
21
            $message .= ": $error";
22
        }
23
24
        return new static($message);
25
    }
26
27
    /**
28
     * @param array $response
29
     *
30
     * @return static
31
     */
32
    public static function serviceRespondedWithAnApiError(array $response)
33
    {
34
        return new static("Discord responded with an API error: {$response['code']}: {$response['message']}");
35
    }
36
37
    /**
38
     * @param \Exception $exception
39
     *
40
     * @return static
41
     */
42
    public static function serviceCommunicationError(Exception $exception)
43
    {
44
        return new static("Communication with Discord failed: {$exception->getCode()}: {$exception->getMessage()}");
45
    }
46
}
47