SMSOfficeChannel::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Gabievi\LaravelSMSOffice;
4
5
use Illuminate\Notifications\Notification;
6
use Gabievi\LaravelSMSOffice\Exceptions\MissingRecipient;
7
8
class SMSOfficeChannel
9
{
10
    /** @var \Gabievi\LaravelSMSOffice\SMSOffice */
11
    protected $smsoffice;
12
13
    /**
14
     * SMSOfficeChannel constructor.
15
     * @param SMSOffice $smsoffice
16
     */
17 3
    public function __construct(SMSOffice $smsoffice)
18
    {
19 3
        $this->smsoffice = $smsoffice;
20 3
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     * @throws MissingRecipient
28
     */
29 3
    public function send($notifiable, Notification $notification)
30
    {
31 3
        $to = $notifiable->routeNotificationFor('smsoffice');
32
33 3
        if (empty($to)) {
34 1
            throw new MissingRecipient;
35
        }
36
37 2
        $message = $notification->toSMSOffice($notifiable);
0 ignored issues
show
Bug introduced by
The method toSMSOffice() does not exist on Illuminate\Notifications\Notification. It seems like you code against a sub-type of Illuminate\Notifications\Notification such as Gabievi\LaravelSMSOffice...cationWithInlineMessage or Gabievi\LaravelSMSOffice\Tests\TestNotification. ( Ignorable by Annotation )

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

37
        $message = $notification->/** @scrutinizer ignore-call */ toSMSOffice($notifiable);
Loading history...
38
39 2
        if (is_string($message)) {
40 1
            $message = new SMSOfficeMessage($message);
41
        }
42
43 2
        $this->sendMessage($to, $message);
44 2
    }
45
46
    /**
47
     * @param $recipient
48
     * @param SMSOfficeMessage $message
49
     */
50 2
    protected function sendMessage($recipient, SMSOfficeMessage $message)
51
    {
52 2
        if (strpos($recipient, '+') === 0) {
53 2
            $recipient = substr($recipient, 1);
54
        }
55
56 2
        if (strpos($recipient, '00') === 0) {
57 2
            $recipient = substr($recipient, 2);
58
        }
59
60
        $params = [
61 2
            'destination' => urlencode($recipient),
62 2
            'content'     => $message->content,
63
        ];
64
65 2
        $this->smsoffice->send($params);
66 2
    }
67
}
68