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 (#15)
by
unknown
06:44
created

SmscRuChannel::formatTimeZone()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
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
        $to = $notifiable->routeNotificationFor('smscru');
29
30
        if (empty($to)) {
31
            throw CouldNotSendNotification::missingRecipient();
32
        }
33
34
        $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...
35
36
        if (is_string($message)) {
37
            $message = new SmscRuMessage($message);
38
        }
39
40
        $this->sendMessage($to, $message);
41
    }
42
43
    protected function sendMessage($recipient, SmscRuMessage $message)
44
    {
45
        if (mb_strlen($message->content) > 800) {
46
            throw CouldNotSendNotification::contentLengthLimitExceeded();
47
        }
48
49
        $params = [
50
            'phones'  => $recipient,
51
            'mes'     => $message->content,
52
            'sender'  => $message->from,
53
        ];
54
55
        if ($message->time) {
56
            $params['time'] = '0'.$message->time->getTimestamp();
57
        }
58
59
        if ($message->tz) {
60
            $params['tz'] = $this->formatTimeZone($message->tz);
61
        }
62
63
        $this->smsc->send($params);
64
    }
65
66
    /**
67
     * Calculate SMSC.ru specific timezone difference.
68
     *
69
     * @param \DateTimeZone $tz
70
     * @return int
71
     */
72
    protected function formatTimeZone(\DateTimeZone $tz)
73
    {
74
        $now = date_create();
75
76
        return $tz->getOffset($now) - timezone_open('Europe/Moscow')->getOffset($now);
77
    }
78
}
79