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
Pull Request — master (#43)
by
unknown
05:33 queued 04:30
created

SmscRuChannel   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 92.31%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 3
dl 0
loc 77
ccs 24
cts 26
cp 0.9231
rs 10
c 0
b 0
f 0

4 Methods

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