SMS77Channel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 55
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 31 6
1
<?php
2
3
namespace NotificationChannels\SMS77;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\SMS77\Exceptions\CouldNotSendNotification;
7
8
class SMS77Channel
9
{
10
    /**
11
     * @var SMS77
12
     */
13
    protected $sms77;
14
15
    /**
16
     * @param SMS77 $sms77
17
     */
18
    public function __construct(SMS77 $sms77)
19
    {
20
        $this->sms77 = $sms77;
21
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @throws \NotificationChannels\SMS77\Exceptions\CouldNotSendNotification
30
     */
31
    public function send($notifiable, Notification $notification)
32
    {
33
        $message = $notification->toSms77($notifiable);
0 ignored issues
show
Bug introduced by
The method toSms77() 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...
34
35
        // No SMS77Message object was returned
36
        if (is_string($message)) {
37
            $message = SMS77Message::create($message);
38
        }
39
40
        if (! $message->hasToNumber()) {
41
            if (! $to = $notifiable->phone_number) {
42
                $to = $notifiable->routeNotificationFor('sms');
43
            }
44
45
            if (! $to) {
46
                throw CouldNotSendNotification::phoneNumberNotProvided();
47
            }
48
49
            $message->to($to);
50
        }
51
52
        $params = $message->toArray();
53
54
        if ($message instanceof SMS77Message) {
55
            $response = $this->sms77->sendMessage($params);
56
        } else {
57
            return;
58
        }
59
60
        return json_decode($response->getBody()->getContents(), true);
61
    }
62
}
63