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 | * @param int $code |
||
14 | * @param \Exception $exception |
||
15 | * |
||
16 | * @return static |
||
17 | */ |
||
18 | 1 | public static function serviceRespondedWithAnHttpError(ResponseInterface $response, $code, $exception) |
|
19 | { |
||
20 | 1 | $message = "Discord responded with an HTTP error: {$response->getStatusCode()}"; |
|
21 | |||
22 | 1 | if ($error = Arr::get(json_decode($response->getBody(), true), 'message')) { |
|
23 | 1 | $message .= ": $error"; |
|
24 | } |
||
25 | |||
26 | 1 | return new static($message, $code, $exception); |
|
27 | } |
||
28 | |||
29 | /** |
||
30 | * @param array $response |
||
31 | * @param int $code |
||
32 | * |
||
33 | * @return static |
||
34 | */ |
||
35 | 1 | public static function serviceRespondedWithAnApiError(array $response, $code, $exception = null) |
|
0 ignored issues
–
show
|
|||
36 | { |
||
37 | 1 | return new static("Discord responded with an API error: {$response['code']}: {$response['message']}", $code); |
|
38 | } |
||
39 | |||
40 | /** |
||
41 | * @param \Exception $exception |
||
42 | * |
||
43 | * @return static |
||
44 | */ |
||
45 | 2 | public static function serviceCommunicationError(Exception $exception) |
|
46 | { |
||
47 | 2 | return new static("Communication with Discord failed: {$exception->getCode()}: {$exception->getMessage()}", $exception->getCode(), $exception); |
|
48 | } |
||
49 | } |
||
50 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.