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 ( 28f2de...ba01be )
by Peter
18s queued 11s
created

MessagebirdChannel   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 57
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 65.22%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 5
dl 0
loc 57
ccs 15
cts 23
cp 0.6522
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B send() 0 35 6
1
<?php
2
3
namespace NotificationChannels\Messagebird;
4
5
use Illuminate\Contracts\Events\Dispatcher;
6
use Illuminate\Notifications\Events\NotificationFailed;
7
use Illuminate\Notifications\Notification;
8
use NotificationChannels\Messagebird\Exceptions\CouldNotSendNotification;
9
10
class MessagebirdChannel
11
{
12
    /** @var \NotificationChannels\Messagebird\MessagebirdClient */
13
    protected $client;
14
    private $dispatcher;
15
16 3
    public function __construct(MessagebirdClient $client, Dispatcher $dispatcher = null)
17
    {
18 3
        $this->client = $client;
19 3
        $this->dispatcher = $dispatcher;
20 3
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @return object with response body data if succesful response from API | empty array if not
29
     * @throws \NotificationChannels\MessageBird\Exceptions\CouldNotSendNotification
30
     */
31 2
    public function send($notifiable, Notification $notification)
32
    {
33 2
        $message = $notification->toMessagebird($notifiable);
0 ignored issues
show
Bug introduced by
The method toMessagebird() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
34
35 2
        $data = [];
36
37 2
        if (is_string($message)) {
38 1
            $message = MessagebirdMessage::create($message);
39
        }
40
41 2
        if ($to = $notifiable->routeNotificationFor('messagebird')) {
42 2
            $message->setRecipients($to);
43
        }
44
45
        try {
46 2
            $data = $this->client->send($message);
47
48 2
            if ($this->dispatcher !== null) {
49 2
                $this->dispatcher->dispatch('messagebird-sms', [$notifiable, $notification, $data]);
50
            }
51
        } catch (CouldNotSendNotification $e) {
52
            if ($this->dispatcher !== null) {
53
                $this->dispatcher->dispatch(
54
                    new NotificationFailed(
55
                        $notifiable,
56
                        $notification,
57
                        'messagebird-sms',
58
                        $e->getMessage()
0 ignored issues
show
Documentation introduced by
$e->getMessage() is of type string, but the function expects a array.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
59
                    )
60
                );
61
            }
62
        }
63
64 2
        return $data;
65
    }
66
}
67