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   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 73.68%

Importance

Changes 5
Bugs 2 Features 2
Metric Value
wmc 5
c 5
b 2
f 2
lcom 1
cbo 3
dl 0
loc 42
ccs 14
cts 19
cp 0.7368
rs 10

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 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