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

Twilio::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 2
crap 1
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
     * @var TwilioConfig
17
     */
18
    private $config;
19
20
    /**
21
     * Twilio constructor.
22
     *
23
     * @param  TwilioService $twilioService
24
     * @param TwilioConfig   $config
25
     */
26
    public function __construct(TwilioService $twilioService, TwilioConfig $config)
27 7
    {
28
        $this->twilioService = $twilioService;
29 7
        $this->config = $config;
30 7
    }
31 7
32
    /**
33
     * Send a TwilioMessage to the a phone number.
34
     *
35
     * @param  TwilioMessage $message
36
     * @param                $to
37
     * @param bool           $useAlphanumericSender
38
     * @return mixed
39
     * @throws CouldNotSendNotification
40
     */
41 6
    public function sendMessage(TwilioMessage $message, $to, $useAlphanumericSender = false)
42
    {
43 6
        if ($message instanceof TwilioSmsMessage) {
44 3
            if ($useAlphanumericSender && $sender = $this->getAlphanumericSender()) {
45
                $message->from($sender);
46
            }
47 3
48 2
            return $this->sendSmsMessage($message, $to);
49
        }
50
51 1
        if ($message instanceof TwilioCallMessage) {
52
            return $this->makeCall($message, $to);
53
        }
54 3
55
        throw CouldNotSendNotification::invalidMessageObject($message);
56 3
    }
57 3
58
    protected function sendSmsMessage($message, $to)
59 2
    {
60
        return $this->twilioService->account->messages->sendMessage(
61
            $this->getFrom($message),
62
            $to,
63 2
            trim($message->content),
64
            null,
65 2
            $this->config->getSmsParams()
66 2
        );
67
    }
68 2
69
    protected function makeCall($message, $to)
70
    {
71
        return $this->twilioService->account->calls->create(
72 5
            $this->getFrom($message),
73
            $to,
74 5
            trim($message->content)
75 1
        );
76
    }
77
78 4
    protected function getFrom($message)
79
    {
80
        if (! $from = $message->getFrom() ?: $this->config->getFrom()) {
81
            throw CouldNotSendNotification::missingFrom();
82
        }
83
84
        return $from;
85
    }
86
87
    protected function getAlphanumericSender()
88
    {
89
        if ($sender = $this->config->getAlphanumericSender()) {
90
            return $sender;
91
        }
92
93
        return null;
94
    }
95
}
96