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   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 5
Bugs 1 Features 1
Metric Value
wmc 8
c 5
b 1
f 1
lcom 1
cbo 4
dl 0
loc 45
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
C send() 0 26 7
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