Completed
Pull Request — master (#19)
by Adam
03:03 queued 01:45
created

WebhookChannel   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 3
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 36
ccs 0
cts 16
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 14 2
1
<?php
2
3
namespace NotificationChannels\Webhook;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Support\Arr;
7
use Illuminate\Notifications\Notification;
8
9
class WebhookChannel
10
{
11
    /** @var Client */
12
    protected $client;
13
14
    /**
15
     * @param Client $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
     * @return \GuzzleHttp\Psr7\Response
29
     */
30
    public function send($notifiable, Notification $notification)
31
    {
32
        if (! $url = $notifiable->routeNotificationFor('Webhook')) {
33
            return;
34
        }
35
36
        $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...
37
38
        return $this->client->post($url, [
39
            'body' => json_encode(Arr::get($webhookData, 'data')),
40
            'verify' => false,
41
            'headers' => Arr::get($webhookData, 'headers'),
42
        ]);
43
    }
44
}
45