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
Pull Request — master (#16)
by
unknown
16:22
created

MessagebirdClient   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 3
dl 0
loc 42
ccs 0
cts 24
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 20 4
1
<?php
2
3
namespace NotificationChannels\Messagebird;
4
5
use Exception;
6
use GuzzleHttp\Client;
7
use NotificationChannels\Messagebird\Exceptions\CouldNotSendNotification;
8
9
class MessagebirdClient
10
{
11
    protected $client;
12
    protected $access_key;
13
14
    /**
15
     * MessagebirdClient constructor.
16
     * @param Client $client
17
     * @param $access_key string API Key from Messagebird API
18
     */
19
    public function __construct(Client $client, $access_key)
20
    {
21
        $this->client = $client;
22
        $this->access_key = $access_key;
23
    }
24
25
    /**
26
     * Send the Message.
27
     * @param MessagebirdMessage $message
28
     * @throws CouldNotSendNotification
29
     */
30
    public function send(MessagebirdMessage $message)
31
    {
32
        if (empty($message->originator)) {
33
            $message->setOriginator(config('services.messagebird.originator'));
34
        }
35
        if (empty($message->recipients)) {
36
            $message->setRecipients(config('services.messagebird.recipients'));
37
        }
38
39
        try {
40
            $this->client->request('POST', 'https://rest.messagebird.com/messages', [
41
                'body' => $message->toJson(),
42
                'headers' => [
43
                    'Authorization' => 'AccessKey '.$this->access_key,
44
                ],
45
            ]);
46
        } catch (Exception $exception) {
47
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
48
        }
49
    }
50
}
51