AllMySmsChannel   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 62
ccs 14
cts 16
cp 0.875
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A send() 0 20 5
A __construct() 0 5 1
1
<?php
2
3
namespace NotificationChannels\AllMySms;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\AllMySms\Exceptions\CouldNotSendNotification;
7
8
class AllMySmsChannel
9
{
10
    /** @var \NotificationChannels\AllMySms\AllMySms */
11
    protected $client;
12
13
    /**
14
     * The sender name the message should sent from.
15
     *
16
     * @var string|null
17
     */
18
    public $sender;
19
20
    /**
21
     * The phone number the message should always send to.
22
     *
23
     * @var string|null
24
     */
25
    protected $to;
26
27
    /**
28
     * Create a new AllMySmsChannel instance.
29
     *
30
     * @param  \NotificationChannels\AllMySms\AllMySms  $client
31
     * @param  string|null  $sender
32
     * @param  string|null  $to
33
     */
34 2
    public function __construct(AllMySms $client, ?string $sender = null, ?string $to = null)
35
    {
36 2
        $this->client = $client;
37 2
        $this->sender = $sender;
38 2
        $this->to = $to;
39 2
    }
40
41
    /**
42
     * Send the given notification.
43
     *
44
     * @param mixed $notifiable
45
     * @param \Illuminate\Notifications\Notification $notification
46
     * @return void
47
     *
48
     * @throws \NotificationChannels\AllMySms\Exceptions\CouldNotSendNotification
49
     */
50 2
    public function send($notifiable, Notification $notification)
51
    {
52 2
        if (! $to = $notifiable->routeNotificationFor('AllMySms', $notification)) {
53
            return;
54
        }
55
56 2
        if (! empty($this->to)) {
57
            $to = $this->to;
58
        }
59
60 2
        $message = $notification->toAllMySms($notifiable);
0 ignored issues
show
introduced by
The method toAllMySms() does not exist on Illuminate\Notifications\Notification. Are you sure you never get this type here, but always one of the subclasses? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

60
        /** @scrutinizer ignore-call */ 
61
        $message = $notification->toAllMySms($notifiable);
Loading history...
61
62 2
        if (is_string($message)) {
63 2
            $message = new AllMySmsMessage($message);
64
        }
65
66 2
        $response = $this->client->sendSms($to, $message->toArray(), $this->sender);
67
68 2
        if ($response->getStatusCode() !== 200) {
69 2
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
70
        }
71
    }
72
}
73