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 ( 0bf2c9...433085 )
by Jhao
01:34
created

SmscRuChannel::getRecipients()   A

Complexity

Conditions 4
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

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