Completed
Pull Request — master (#19)
by Adam
02:14
created

WebhookChannel::send()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2.0116

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 14
ccs 6
cts 7
cp 0.8571
rs 9.4285
cc 2
eloc 8
nc 2
nop 2
crap 2.0116
1
<?php
2
3
namespace NotificationChannels\Webhook;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Support\Arr;
7
use NotificationChannels\Webhook\Exceptions\CouldNotSendNotification;
8
use Illuminate\Notifications\Notification;
9
10
class WebhookChannel
11
{
12
    /** @var Client */
13
    protected $client;
14
15
    /**
16
     * @param Client $client
17
     */
18 3
    public function __construct(Client $client)
19
    {
20 3
        $this->client = $client;
21 3
    }
22
23
    /**
24
     * Send the given notification.
25
     *
26
     * @param mixed $notifiable
27
     * @param \Illuminate\Notifications\Notification $notification
28
     *
29
     * @return \GuzzleHttp\Psr7\Response
30
     */
31 3
    public function send($notifiable, Notification $notification)
32
    {
33 3
        if (! $url = $notifiable->routeNotificationFor('Webhook')) {
34
            return;
35
        }
36
37 3
        $webhookData = $notification->toWebhook($notifiable)->toArray();
0 ignored issues
show
Bug introduced by
The method toWebhook() 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...
38
39 3
        return $this->client->post($url, [
40 3
            'body' => json_encode(Arr::get($webhookData, 'data')),
41
            'verify' => false,
42 3
            'headers' => Arr::get($webhookData, 'headers'),
43
        ]);
44
    }
45
}
46