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 (#17)
by Casper
08:08
created

Twilio   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 73
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 9
c 2
b 1
f 1
lcom 1
cbo 1
dl 0
loc 73
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A sendMessage() 0 12 3
A sendSmsMessage() 0 8 1
A makeCall() 0 8 1
A getFrom() 0 8 3
1
<?php
2
3
namespace NotificationChannels\Twilio;
4
5
use NotificationChannels\Twilio\Exceptions\CouldNotSendNotification;
6
use Services_Twilio as TwilioService;
7
8
class Twilio
9
{
10
    /**
11
     * @var TwilioService
12
     */
13
    protected $twilioService;
14
15
    /**
16
     * Default 'from' from config.
17
     * @var string
18
     */
19
    protected $from;
20
21
    /**
22
     * Twilio constructor.
23
     *
24
     * @param  TwilioService  $twilioService
25
     * @param  string  $from
26
     */
27
    public function __construct(TwilioService $twilioService, $from)
28
    {
29
        $this->twilioService = $twilioService;
30
        $this->from = $from;
31
    }
32
33
    /**
34
     * Send a TwilioMessage to the a phone number.
35
     *
36
     * @param  TwilioMessage  $message
37
     * @param  $to
38
     * @return mixed
39
     * @throws CouldNotSendNotification
40
     */
41
    public function sendMessage(TwilioMessage $message, $to)
42
    {
43
        if ($message instanceof TwilioSmsMessage) {
44
            return $this->sendSmsMessage($message, $to);
45
        }
46
47
        if ($message instanceof TwilioCallMessage) {
48
            return $this->makeCall($message, $to);
49
        }
50
51
        throw CouldNotSendNotification::invalidMessageObject($message);
52
    }
53
54
    protected function sendSmsMessage($message, $to)
55
    {
56
        return $this->twilioService->account->messages->sendMessage(
57
            $this->getFrom($message),
58
            $to,
59
            trim($message->content)
60
        );
61
    }
62
63
    protected function makeCall($message, $to)
64
    {
65
        return $this->twilioService->account->calls->create(
66
            $this->getFrom($message),
67
            $to,
68
            trim($message->content)
69
        );
70
    }
71
72
    protected function getFrom($message)
73
    {
74
        if (! $from = $message->from ?: $this->from) {
75
            throw CouldNotSendNotification::missingFrom();
76
        }
77
78
        return $from;
79
    }
80
}
81