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.

MessagebirdClient   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 23.53%

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 5
dl 0
loc 48
ccs 4
cts 17
cp 0.2353
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A send() 0 25 5
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 5
    public function __construct(Client $client, $access_key)
20
    {
21 5
        $this->client = $client;
22 5
        $this->access_key = $access_key;
23 5
    }
24
25
    /**
26
     * Send the Message.
27
     * @param MessagebirdMessage $message
28
     * @return
29
     * @throws CouldNotSendNotification
30
     */
31
    public function send(MessagebirdMessage $message)
32
    {
33
        if (empty($message->originator)) {
34
            $message->setOriginator(config('services.messagebird.originator'));
35
        }
36
        if (empty($message->recipients)) {
37
            $message->setRecipients(config('services.messagebird.recipients'));
38
        }
39
        if (empty($message->datacoding)) {
0 ignored issues
show
Bug introduced by
The property datacoding does not seem to exist in NotificationChannels\Mes...bird\MessagebirdMessage.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
40
            $message->setDatacoding('auto');
41
        }
42
43
        try {
44
            $response = $this->client->request('POST', 'https://rest.messagebird.com/messages', [
45
                'body' => $message->toJson(),
46
                'headers' => [
47
                    'Authorization' => 'AccessKey '.$this->access_key,
48
                ],
49
            ]);
50
51
            return json_decode($response->getBody()->__toString());
52
        } catch (Exception $exception) {
53
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
54
        }
55
    }
56
}
57