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 ( 513b86...a0fe62 )
by Peter
04:01
created

MessagebirdChannel::send()   C

Complexity

Conditions 7
Paths 32

Size

Total Lines 26
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 26
rs 6.7272
cc 7
eloc 16
nc 32
nop 2
1
<?php
2
3
namespace NotificationChannels\Messagebird;
4
5
use Exception;
6
use Illuminate\Notifications\Notification;
7
use MessageBird\Exceptions\AuthenticateException;
8
use MessageBird\Exceptions\BalanceException;
9
use NotificationChannels\Messagebird\Exceptions\CouldNotSendNotification;
10
use MessageBird\Client;
11
12
class MessagebirdChannel
13
{
14
    /** @var \MessageBird\Client */
15
    protected $client;
16
17
    public function __construct(Client $client)
18
    {
19
        $this->client = $client;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @throws \NotificationChannels\MessageBird\Exceptions\CouldNotSendNotification
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        $message = $notification->toMessagebird($notifiable);
33
34
        if (is_string($message)) {
35
            $message = MessagebirdMessage::create($message);
36
        }
37
38
        if (empty($message->originator)) {
39
            $message->setOriginator(config('services.messagebird.originator'));
40
        }
41
42
        if (empty($message->recipients)) {
43
            $message->setRecipients(config('services.messagebird.recipients'));
44
        }
45
46
        try {
47
            $this->client->messages->create($message);
48
        } catch (AuthenticateException $exception) {
49
            throw CouldNotSendNotification::couldNotAuthenticate();
50
        } catch (BalanceException $exception) {
51
            throw CouldNotSendNotification::notEnoughCredits();
52
        } catch (Exception $exception) {
53
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
54
        }
55
    }
56
}
57