SmsUpChannel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
c 3
b 0
f 0
dl 0
loc 36
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 2 1
A send() 0 22 3
1
<?php
2
3
namespace SquareetLabs\LaravelSmsUp;
4
5
use Illuminate\Support\Facades\Event;
6
use SquareetLabs\LaravelSmsUp\Events\SmsUpMessageWasSent;
7
use SquareetLabs\LaravelSmsUp\Exceptions\CouldNotSendNotification;
8
use Illuminate\Notifications\Notification;
9
use SquareetLabs\LaravelSmsUp\Facades;
10
11
/**
12
 * Class SmsUpChannel
13
 * @package SquareetLabs\LaravelSmsUp
14
 */
15
class SmsUpChannel
16
{
17
    /**
18
     * SmsUpChannel constructor.
19
     */
20
    public function __construct()
21
    {
22
    }
23
24
    /**
25
     * @param $notifiable
26
     * @param Notification $notification
27
     * @throws CouldNotSendNotification
28
     */
29
    public function send($notifiable, Notification $notification)
30
    {
31
        /** @var SmsUpMessage $message */
32
        $message = $notification->toSmsUp($notifiable);
0 ignored issues
show
Bug introduced by
The method toSmsUp() does not exist on Illuminate\Notifications\Notification. ( Ignorable by Annotation )

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

32
        /** @scrutinizer ignore-call */ 
33
        $message = $notification->toSmsUp($notifiable);

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...
33
34
        if (empty($message->getTo())) {
35
            if (!$to = $notifiable->routeNotificationFor('smsUp')) {
36
                throw CouldNotSendNotification::missingRecipient();
37
            }
38
            $message->to($to);
39
        }
40
41
        $messages = [
42
            $message->formatData()
43
        ];
44
        $response = Facades\SmsUp::sendMessages($messages);
0 ignored issues
show
Bug introduced by
The method sendMessages() does not exist on SquareetLabs\LaravelSmsUp\Facades\SmsUp. Since you implemented __callStatic, consider adding a @method annotation. ( Ignorable by Annotation )

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

44
        /** @scrutinizer ignore-call */ 
45
        $response = Facades\SmsUp::sendMessages($messages);
Loading history...
45
46
        $responseArray = [];
47
        array_push($responseArray, json_decode($response->getBody(), true));
48
        $reponseMessage = new SmsUpResponse($responseArray[0]);
49
50
        Event::dispatch(new SmsUpMessageWasSent($message, $reponseMessage));
51
    }
52
}
53