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 ( 977b4e...210f22 )
by Jhao
06:32 queued 05:34
created

SmscRuChannel::sendMessage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
dl 0
loc 18
ccs 9
cts 10
cp 0.9
rs 9.6666
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 3.009
1
<?php
2
3
namespace NotificationChannels\SmscRu;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\SmscRu\Exceptions\CouldNotSendNotification;
7
8
class SmscRuChannel
9
{
10
    /** @var SmscRuApi */
11
    protected $smsc;
12
13 4
    public function __construct(SmscRuApi $smsc)
14
    {
15 4
        $this->smsc = $smsc;
16 4
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param  mixed  $notifiable
22
     * @param  Notification  $notification
23
     *
24
     * @return void
25
     */
26 4
    public function send($notifiable, Notification $notification)
27
    {
28 4
        if (! ($to = $this->getRecipients($notifiable, $notification))) {
29 1
            return;
30
        }
31
32 3
        $message = $notification->{'toSmscRu'}($notifiable);
33
34 3
        if (\is_string($message)) {
35
            $message = new SmscRuMessage($message);
36
        }
37
38 3
        $this->sendMessage($to, $message);
39 3
    }
40
41
    /**
42
     * Gets a list of phones from the given notifiable.
43
     *
44
     * @param  mixed  $notifiable
45
     * @param  Notification  $notification
46
     *
47
     * @return string[]
48
     */
49 4
    protected function getRecipients($notifiable, Notification $notification)
50
    {
51 4
        $to = $notifiable->routeNotificationFor('smscru', $notification);
52
53 4
        if ($to === null || $to === false || $to === '') {
54 1
            return [];
55
        }
56
57 3
        return \is_array($to) ? $to : [$to];
58
    }
59
60 3
    protected function sendMessage($recipients, SmscRuMessage $message)
61
    {
62 3
        if (\mb_strlen($message->content) > 800) {
63
            throw CouldNotSendNotification::contentLengthLimitExceeded();
64
        }
65
66
        $params = [
67 3
            'phones'  => \implode(',', $recipients),
68 3
            'mes'     => $message->content,
69 3
            'sender'  => $message->from,
70
        ];
71
72 3
        if ($message->sendAt instanceof \DateTimeInterface) {
73 1
            $params['time'] = '0'.$message->sendAt->getTimestamp();
74
        }
75
76 3
        $this->smsc->send($params);
77 3
    }
78
}
79