SmspohChannel   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 18
c 1
b 0
f 0
dl 0
loc 58
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 21 6
1
<?php
2
3
namespace NotificationChannels\Smspoh;
4
5
use Illuminate\Notifications\Notification;
6
use NotificationChannels\Smspoh\Exceptions\CouldNotSendNotification;
7
8
class SmspohChannel
9
{
10
    /**
11
     * The Smspoh client instance.
12
     *
13
     * @var SmspohApi
14
     */
15
    protected $smspoh;
16
17
    /**
18
     * The phone number notifications should be sent from.
19
     *
20
     * @var string
21
     */
22
    protected $sender;
23
24
    /**
25
     * @var int
26
     * The message body content count should be no longer than 6 message parts(918).
27
     */
28
    protected $character_limit_count = 918;
29
30 5
    public function __construct(SmspohApi $smspoh, $sender)
31
    {
32 5
        $this->smspoh = $smspoh;
33 5
        $this->sender = $sender;
34 5
    }
35
36
    /**
37
     * Send the given notification.
38
     *
39
     * @param mixed $notifiable
40
     * @param Notification $notification
41
     *
42
     * @return mixed|\Psr\Http\Message\ResponseInterface|void
43
     * @throws CouldNotSendNotification
44
     */
45 5
    public function send($notifiable, Notification $notification)
46
    {
47 5
        if (! $to = $notifiable->routeNotificationFor('smspoh', $notification)) {
48 1
            return;
49
        }
50
51 4
        $message = $notification->toSmspoh($notifiable);
0 ignored issues
show
Bug introduced by
The method toSmspoh() does not exist on Illuminate\Notifications\Notification. It seems like you code against a sub-type of said class. However, the method does not exist in Illuminate\Auth\Notifications\ResetPassword or Illuminate\Auth\Notifications\VerifyEmail. Are you sure you never get one of those? ( Ignorable by Annotation )

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

51
        /** @scrutinizer ignore-call */ 
52
        $message = $notification->toSmspoh($notifiable);
Loading history...
52
53 4
        if (is_string($message)) {
54 1
            $message = new SmspohMessage($message);
55
        }
56
57 4
        if (mb_strlen($message->content) > $this->character_limit_count) {
58 1
            throw CouldNotSendNotification::contentLengthLimitExceeded($this->character_limit_count);
59
        }
60
61 3
        return $this->smspoh->send([
62 3
            'sender' => $message->sender ?: $this->sender,
63 3
            'to' => $to,
64 3
            'message' => trim($message->content),
65 3
            'test' => $message->test ?: false,
66
        ]);
67
    }
68
}
69