Completed
Pull Request — master (#1)
by Chris
01:15
created

GlobeLabsSmsChannel::send()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 23
rs 8.5906
cc 5
eloc 12
nc 4
nop 2
1
<?php
2
3
namespace Coreproc\GlobeLabsSms;
4
5
use GuzzleHttp\Client;
6
use GuzzleHttp\Exception\GuzzleException;
7
use Illuminate\Notifications\Notification;
8
use Coreproc\GlobeLabsSms\Exceptions\CouldNotSendNotification;
9
10
class GlobeLabsSmsChannel
11
{
12
    /**
13
     * @var Client
14
     */
15
    protected $client;
16
17
    public function __construct(Client $client)
18
    {
19
        $this->client = $client;
20
    }
21
22
    /**
23
     * Send the given notification.
24
     *
25
     * @param mixed $notifiable
26
     * @param \Illuminate\Notifications\Notification $notification
27
     *
28
     * @throws CouldNotSendNotification
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        if (empty($notifiable->routeNotificationFor('globeLabsSms'))) {
33
            throw new CouldNotSendNotification('Missing method in your notifiable: routeNotificationForGlobeLabs().');
34
        }
35
36
        $contactInfo = $notifiable->routeNotificationFor('globeLabsSms');
37
38
        // The contact info should include an access_token and a address
39
        if (empty($contactInfo['access_token']) || empty($contactInfo['address'])) {
40
            throw new CouldNotSendNotification('Missing variables from your routeNotificationForGlobeLabs().');
41
        }
42
43
        $message = $notification->toGlobeLabsSms($notifiable);
0 ignored issues
show
Bug introduced by
The method toGlobeLabsSms() 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...
44
45
        try {
46
            $this->client->request('POST', $message->getApiSendUrl(), [
47
                'body' => $message->toJson(),
48
            ]);
49
        } catch (GuzzleException $exception) {
50
            throw new CouldNotSendNotification($exception->getMessage());
51
        }
52
    }
53
}
54