JusibeChannel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

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
     * Create a new Jusibe channel instance.
28
     *
29
     * @param  JusibeClient  $jusibe
30
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

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