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 ( a14aa2...098aef )
by Peter
07:47
created

MessagebirdClient::send()   A

Complexity

Conditions 4
Paths 8

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 4.5923

Importance

Changes 4
Bugs 1 Features 2
Metric Value
c 4
b 1
f 2
dl 0
loc 20
ccs 10
cts 15
cp 0.6667
rs 9.2
cc 4
eloc 12
nc 8
nop 1
crap 4.5923
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 4
    public function __construct(Client $client, $access_key)
20
    {
21 4
        $this->client = $client;
22 4
        $this->access_key = $access_key;
23 4
    }
24
25
    /**
26
     * Send the Message.
27
     * @param MessagebirdMessage $message
28
     * @throws CouldNotSendNotification
29
     */
30 1
    public function send(MessagebirdMessage $message)
31
    {
32 1
        if (empty($message->originator)) {
33
            $message->setOriginator(config('services.messagebird.originator'));
34
        }
35 1
        if (empty($message->recipients)) {
36
            $message->setRecipients(config('services.messagebird.recipients'));
37
        }
38
39
        try {
40 1
            $this->client->request('POST', 'https://rest.messagebird.com/messages', [
41 1
                'body' => $message->toJson(),
42
                'headers' => [
43 1
                    'Authorization' => 'AccessKey '.$this->access_key
44 1
                ],
45 1
            ]);
46 1
        } catch (Exception $exception) {
47
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
48
        }
49 1
    }
50
}
51