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 ( 1d9f08...0bf2c9 )
by Jhao
02:36
created

SmscRuChannel::getRecipients()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 11
cp 0
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 3
nop 2
crap 30
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  \Illuminate\Notifications\Notification  $notification
23
     *
24
     * @throws  \NotificationChannels\SmscRu\Exceptions\CouldNotSendNotification
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);
0 ignored issues
show
Bug introduced by
The method toSmscRu() does not seem to exist on object<Illuminate\Notifications\Notification>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
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  \Illuminate\Notifications\Notification  $notification
46
     *
47
     * @return string[]
48
     */
49
    protected function getRecipients($notifiable, Notification $notification)
50
    {
51
        $to = $notifiable->routeNotificationFor('smscru', $notification);
52
53
        if (is_array($to)) {
54
            return $to;
55
        }
56
57
        if ($to === null || $to === false || $to === '') {
58
            return [];
59
        }
60
61
        return [$to];
62
    }
63
64
    protected function sendMessage($recipients, SmscRuMessage $message)
65
    {
66
        if (\mb_strlen($message->content) > 800) {
67
            throw CouldNotSendNotification::contentLengthLimitExceeded();
68
        }
69
70
        $params = [
71
            'phones'  => implode(',', $recipients),
72
            'mes'     => $message->content,
73
            'sender'  => $message->from,
74
        ];
75
76
        if ($message->sendAt instanceof \DateTimeInterface) {
77
            $params['time'] = '0'.$message->sendAt->getTimestamp();
78
        }
79
80
        $this->smsc->send($params);
81
    }
82
}
83