JusibeChannel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 52.63%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 2
dl 0
loc 62
ccs 10
cts 19
cp 0.5263
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 28 6
1
<?php
2
3
namespace NotificationChannels\Jusibe;
4
5
use DomainException;
6
use Illuminate\Notifications\Notification;
7
use NotificationChannels\Jusibe\Exceptions\CouldNotSendNotification;
8
use Unicodeveloper\Jusibe\Jusibe as JusibeClient;
9
10
class JusibeChannel
11
{
12
    /**
13
     * The Jusibe client instance.
14
     *
15
     * @var \Jusibe\Jusibe
16
     */
17
    protected $jusibe;
18
19
    /**
20
     * The phone number notifications should be sent from.
21
     *
22
     * @var string
23
     */
24
    protected $from;
25
26
    /**
27
     * @param  JusibeClient  $jusibe
28
     */
29 3
    public function __construct(JusibeClient $jusibe)
30
    {
31 3
        $this->jusibe = $jusibe;
0 ignored issues
show
Documentation Bug introduced by
It seems like $jusibe of type object<Unicodeveloper\Jusibe\Jusibe> is incompatible with the declared type object<Jusibe\Jusibe> of property $jusibe.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
32 3
    }
33
34
    /**
35
     * Send the given notification.
36
     *
37
     * @param  mixed $notifiable
38
     * @param  \Illuminate\Notifications\Notification $notification
39
     * @return mixed
40
     *
41
     * @throws \NotificationChannels\Jusibe\Exceptions\CouldNotSendNotification
42
     */
43 3
    public function send($notifiable, Notification $notification)
44
    {
45 3
        if (! $to = $notifiable->routeNotificationFor('jusibe')) {
46 1
            throw CouldNotSendNotification::missingTo();
47
        }
48
49 2
        $message = $notification->toJusibe($notifiable);
0 ignored issues
show
Bug introduced by
The method toJusibe() 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...
50
51 2
        if (is_string($message)) {
52
            $message = new JusibeMessage($message);
53
        }
54
55 2
        if (! $from = $message->from ?: config('services.jusibe.sms_from')) {
56 2
            throw CouldNotSendNotification::missingFrom();
57
        }
58
59
        try {
60
            $response = $this->jusibe->sendSMS([
61
                'to' => $to,
62
                'from' => $from,
63
                'message' => trim($message->content),
64
            ])->getResponse();
65
66
            return $response;
67
        } catch (DomainException $exception) {
68
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
69
        }
70
    }
71
}
72