Passed
Push — master ( b9519f...150a9e )
by Farhad
02:36 queued 24s
created

RayganSmsChannel::shouldSendMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
1
<?php
2
3
namespace NotificationChannels\RayganSms;
4
5
use DomainException;
6
use Illuminate\Notifications\Notification;
0 ignored issues
show
Bug introduced by
The type Illuminate\Notifications\Notification was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use NotificationChannels\RayganSms\Events\MessageWasSent;
8
use NotificationChannels\RayganSms\Events\SendingMessage;
9
use NotificationChannels\RayganSms\Exceptions\CouldNotSendNotification;
10
use Trez\RayganSms\Facades\RayganSms;
11
12
class RayganSmsChannel
13
{
14
    public function __construct()
15
    {
16
    }
17
18
    /**
19
     * Send the given notification.
20
     *
21
     * @param mixed        $notifiable
22
     * @param Notification $notification
23
     *
24
     * @return void
25
     */
26
    public function send($notifiable, Notification $notification)
27
    {
28
        if (!$this->shouldSendMessage($notifiable, $notification)) {
29
            return;
30
        }
31
32
        if (!$to = $notifiable->routeNotificationFor('raygansms')) {
33
            return;
34
        }
35
36
        $message = $notification->toRayganSms($notifiable);
37
38
        if (is_string($message)) {
39
            $message = new RayganSmsMessage($message);
40
        }
41
42
        try {
43
            RayganSms::sendMessage($to, $message->getContent());
44
45
            event(new MessageWasSent($notifiable, $notification));
0 ignored issues
show
Bug introduced by
The function event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

45
            /** @scrutinizer ignore-call */ 
46
            event(new MessageWasSent($notifiable, $notification));
Loading history...
46
        } catch (DomainException $e) {
47
            throw CouldNotSendNotification::serviceRespondedWithAnError($e);
48
        }
49
    }
50
51
    /**
52
     * Check if we can send the notification.
53
     *
54
     * @param $notifiable
55
     * @param Notification $notification
56
     *
57
     * @return bool
58
     */
59
    protected function shouldSendMessage($notifiable, Notification $notification)
60
    {
61
        return event(new SendingMessage($notifiable, $notification), [], true) !== false;
0 ignored issues
show
Bug introduced by
The function event was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

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

61
        return /** @scrutinizer ignore-call */ event(new SendingMessage($notifiable, $notification), [], true) !== false;
Loading history...
62
    }
63
}
64