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.

CouldNotSendNotification   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A facebookRespondedWithAnError() 0 10 2
A facebookPageTokenNotProvided() 0 4 1
A couldNotCommunicateWithFacebook() 0 4 1
1
<?php
2
3
namespace NotificationChannels\Facebook\Exceptions;
4
5
use Exception;
6
use GuzzleHttp\Exception\ClientException;
7
8
/**
9
 * Class CouldNotSendNotification.
10
 */
11
class CouldNotSendNotification extends Exception
12
{
13
    /**
14
     * Thrown when there's a bad request and an error is responded.
15
     *
16
     * @param  ClientException  $exception
17
     *
18
     * @return static
19
     */
20
    public static function facebookRespondedWithAnError(ClientException $exception): self
21
    {
22
        if ($exception->hasResponse()) {
23
            $result = json_decode($exception->getResponse()->getBody(), false);
24
25
            return new static("Facebook responded with an error `{$result->error->code} - {$result->error->type} {$result->error->message}`");
26
        }
27
28
        return new static('Facebook responded with an error');
29
    }
30
31
    /**
32
     * Thrown when there's no page token provided.
33
     *
34
     * @param  string  $message
35
     *
36
     * @return static
37
     */
38
    public static function facebookPageTokenNotProvided(string $message): self
39
    {
40
        return new static($message);
41
    }
42
43
    /**
44
     * Thrown when we're unable to communicate with Telegram.
45
     *
46
     * @param  Exception  $exception
47
     *
48
     * @return static
49
     */
50
    public static function couldNotCommunicateWithFacebook(Exception $exception): self
51
    {
52
        return new static('The communication with Facebook failed. Reason: '.$exception->getMessage());
53
    }
54
}
55