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   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 0
loc 71
ccs 0
cts 38
cp 0
rs 10
c 1
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 14 3
A getRecipients() 0 10 4
A sendMessage() 0 18 3
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