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

GlobeLabsSmsChannel   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B send() 0 23 5
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