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 ( 433085...0775a7 )
by Jhao
01:41
created

SmscRuChannel   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 71
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 14 3
B getRecipients() 0 10 5
A sendMessage() 0 18 3
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 \NotificationChannels\SmscRu\SmscRuApi */
11
    protected $smsc;
12
13
    public function __construct(SmscRuApi $smsc)
14
    {
15
        $this->smsc = $smsc;
16
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param  mixed  $notifiable
22
     * @param  Notification  $notification
23
     *
24
     * @return void
25
     */
26
    public function send($notifiable, Notification $notification)
27
    {
28
        if (! ($to = $this->getRecipients($notifiable, $notification))) {
29
            return;
30
        }
31
32
        $message = $notification->{'toSmscRu'}($notifiable);
33
34
        if (\is_string($message)) {
35
            $message = new SmscRuMessage($message);
36
        }
37
38
        $this->sendMessage($to, $message);
39
    }
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
    protected function getRecipients($notifiable, Notification $notification)
50
    {
51
        $to = $notifiable->routeNotificationFor('smscru', $notification);
52
53
        if ($to === null || $to === false || $to === '') {
54
            return [];
55
        }
56
57
        return is_array($to) ? $to : [$to];
58
    }
59
60
    protected function sendMessage($recipients, SmscRuMessage $message)
61
    {
62
        if (\mb_strlen($message->content) > 800) {
63
            throw CouldNotSendNotification::contentLengthLimitExceeded();
64
        }
65
66
        $params = [
67
            'phones'  => \implode(',', $recipients),
68
            'mes'     => $message->content,
69
            'sender'  => $message->from,
70
        ];
71
72
        if ($message->sendAt instanceof \DateTimeInterface) {
73
            $params['time'] = '0'.$message->sendAt->getTimestamp();
74
        }
75
76
        $this->smsc->send($params);
77
    }
78
}
79