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 ( ea1c08...e9e490 )
by Shiro
01:26
created

GoSmsChannel   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 67
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 67
ccs 0
cts 37
cp 0
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 16 3
B sendMessage() 0 31 4
1
<?php
2
3
namespace NotificationChannels\GoSms;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\GoSms\Exceptions\CouldNotSendNotification;
7
8
class GoSmsChannel
9
{
10
    /** @var \NotificationChannels\GoSms\GoSmsApi */
11
    protected $gosms;
12
13
    public function __construct(GoSmsApi $gosms)
14
    {
15
        $this->gosms = $gosms;
16
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param  mixed  $notifiable
22
     * @param  \Illuminate\Notifications\Notification  $notification
23
     *
24
     * @throws  \NotificationChannels\GoSms\Exceptions\CouldNotSendNotification
25
     */
26
    public function send($notifiable, Notification $notification)
27
    {
28
        $to = $notifiable->routeNotificationFor('gosms');
29
30
        if (empty($to)) {
31
            throw CouldNotSendNotification::missingRecipient();
32
        }
33
34
        $message = $notification->toGoSms($notifiable);
0 ignored issues
show
Bug introduced by
The method toGoSms() 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 GoSmsMessage($message);
38
        }
39
40
        $this->sendMessage($to, $message);
41
    }
42
43
    protected function sendMessage($recipient, GoSmsMessage $message)
44
    {
45
        // if (mb_strlen($message->content) > 800) {
0 ignored issues
show
Unused Code Comprehensibility introduced by
53% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
46
        //     throw CouldNotSendNotification::contentLengthLimitExceeded();
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
47
        // }
48
49
        $message->content = html_entity_decode($message->content, ENT_QUOTES, 'utf-8');
50
        $message->content = urlencode($message->content);
51
52
        //the sms format must start with 6
53
        $valid_mobile = '';
54
        if ($recipient[0] == '0') {
55
            $valid_mobile = '6'.$recipient;
56
        }
57
58
        if ($recipient[0] == '+') {
59
            $valid_mobile = substr($recipient, 1);
60
        }
61
62
        $params = [
63
            'hp'        => $valid_mobile,
64
            'mesg'      => $message->content,
65
            'sender'    => $message->from,
66
        ];
67
68
        if ($message->sendAt instanceof \DateTimeInterface) {
69
            $params['time'] = '0'.$message->sendAt->getTimestamp();
70
        }
71
72
        $this->gosms->send($params);
73
    }
74
}
75