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 ( d68656...1c9f1f )
by Freek
02:00
created

TwilioChannel::send()   C

Complexity

Conditions 8
Paths 11

Size

Total Lines 36
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 1 Features 0
Metric Value
c 3
b 1
f 0
dl 0
loc 36
rs 5.3846
cc 8
eloc 19
nc 11
nop 2
1
<?php
2
3
namespace NotificationChannels\Twilio;
4
5
use Exception;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\Twilio\Events\MessageWasSent;
8
use NotificationChannels\Twilio\Events\SendingMessage;
9
use NotificationChannels\Twilio\Exceptions\CouldNotSendNotification;
10
use Services_Twilio;
11
12
class TwilioChannel
13
{
14
    /** @var \Services_Twilio */
15
    protected $twilio;
16
17
    public function __construct(Services_Twilio $twilio)
18
    {
19
        $this->twilio = $twilio;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param  mixed $notifiable
26
     * @param  \Illuminate\Notifications\Notification $notification
27
     *
28
     * @throws CouldNotSendNotification
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        if (!$to = $notifiable->routeNotificationFor('twilio')) {
33
            return;
34
        }
35
36
        $message = $notification->toTwilio($notifiable);
37
38
        if (is_string($message)) {
39
            $message = new TwilioSmsMessage($message);
40
        }
41
42
        if (!in_array(get_class($message), [TwilioSmsMessage::class, TwilioCallMessage::class])) {
43
            throw CouldNotSendNotification::invalidMessageObject($message);
44
        }
45
46
        if (!$from = $message->from ?: config('services.twilio.from')) {
47
            throw CouldNotSendNotification::missingFrom();
48
        }
49
50
        $shouldSendMessage = event(new SendingMessage($notifiable, $notification, $message), [], true) !== false;
51
52
        if (!$shouldSendMessage) {
53
            return;
54
        }
55
56
        $response = null;
57
58
        try {
59
            $response = $this->sendMessage($message, $from, $to);
60
        } catch (Exception $exception) {
61
            throw CouldNotSendNotification::serviceRespondedWithAnException($exception);
62
        }
63
64
        event(new MessageWasSent($notifiable, $notification, $response));
65
    }
66
67
    /**
68
     * @param $message
69
     * @param $from
70
     * @param $to
71
     * @return mixed
72
     *
73
     * @throws \NotificationChannels\Twilio\Exceptions\CouldNotSendNotification
74
     */
75
    protected function sendMessage($message, $from, $to)
76
    {
77
        if ($message instanceof TwilioSmsMessage) {
78
            return $this->twilio->account->messages->sendMessage(
79
                $from,
80
                $to,
81
                trim($message->content)
82
            );
83
            return $response;
0 ignored issues
show
Unused Code introduced by
return $response; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
84
        }
85
86
        if ($message instanceof TwilioCallMessage) {
87
            return $this->twilio->account->calls->create(
88
                $from,
89
                $to,
90
                trim($message->url)
91
            );
92
        }
93
94
        throw CouldNotSendNotification::invalidMessageObject($message);
95
    }
96
}
97