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
Pull Request — master (#15)
by
unknown
04:36
created

TwilioChannel   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 5
dl 0
loc 79
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
B send() 0 22 4
A getTo() 0 11 3
A canReceiveAlphanumericSender() 0 5 2
1
<?php
2
3
namespace NotificationChannels\Twilio;
4
5
use Exception;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Contracts\Events\Dispatcher;
8
use NotificationChannels\Twilio\Exceptions\CouldNotSendNotification;
9
use Illuminate\Notifications\Events\NotificationFailed;
10
11
class TwilioChannel
12
{
13
    /**
14
     * @var Twilio
15
     */
16
    protected $twilio;
17
18
    /**
19
     * @var Dispatcher
20
     */
21
    protected $events;
22
23
    /**
24
     * TwilioChannel constructor.
25
     *
26
     * @param Twilio  $twilio
27
     * @param Dispatcher  $events
28
     */
29 7
    public function __construct(Twilio $twilio, Dispatcher $events)
30
    {
31 7
        $this->twilio = $twilio;
32 7
        $this->events = $events;
33 7
    }
34
35
    /**
36
     * Send the given notification.
37
     *
38
     * @param  mixed  $notifiable
39
     * @param  \Illuminate\Notifications\Notification  $notification
40
     * @return mixed
41
     * @throws CouldNotSendNotification
42
     */
43 7
    public function send($notifiable, Notification $notification)
44
    {
45
        try {
46 7
            $to = $this->getTo($notifiable);
47 6
            $message = $notification->toTwilio($notifiable);
48
            $useSender = $this->canReceiveAlphanumericSender($notifiable);
49 6
50 1
            if (is_string($message)) {
51
                $message = new TwilioSmsMessage($message);
52
            }
53 6
54 1
            if (! $message instanceof TwilioMessage) {
55
                throw CouldNotSendNotification::invalidMessageObject($message);
56
            }
57 5
58 2
            return $this->twilio->sendMessage($message, $to, $useSender);
59 2
        } catch (Exception $exception) {
60 2
            $this->events->fire(
61
                new NotificationFailed($notifiable, $notification, 'twilio', ['message' => $exception->getMessage()])
62
            );
63 2
        }
64
    }
65 7
66
    protected function getTo($notifiable)
67 7
    {
68 1
        if ($notifiable->routeNotificationFor('twilio')) {
69
            return $notifiable->routeNotificationFor('twilio');
70 6
        }
71 5
        if (isset($notifiable->phone_number)) {
72
            return $notifiable->phone_number;
73
        }
74 1
75
        throw CouldNotSendNotification::invalidReceiver();
76
    }
77
78
    /**
79
     * Get the alphanumeric sender
80
     * @param $notifiable
81
     * @return mixed|null
82
     * @throws CouldNotSendNotification
83
     */
84
    protected function canReceiveAlphanumericSender($notifiable)
85
    {
86
        return (method_exists($notifiable, 'canReceiveAlphanumericSender') &&
87
            $notifiable->canReceiveAlphanumericSender());
88
    }
89
}
90