HangoutsChatChannel   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 86.67%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 4
dl 0
loc 45
ccs 13
cts 15
cp 0.8667
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A send() 0 21 4
1
<?php
2
3
namespace NotificationChannels;
4
5
use GuzzleHttp\Client;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Support\Arr;
8
use NotificationChannels\Exceptions\CouldNotSendNotification;
9
use Psr\Http\Message\ResponseInterface;
10
11
class HangoutsChatChannel
12
{
13
    /** @var Client */
14
    protected $client;
15
16
    /**
17
     * @param Client $client
18
     */
19 1
    public function __construct(Client $client)
20
    {
21 1
        $this->client = $client;
22 1
    }
23
24
    /**
25
     * Send the given notification.
26
     *
27
     * @param mixed $notifiable
28
     * @param Notification $notification
29
     *
30
     * @return ResponseInterface|void
31
     *
32
     * @throws CouldNotSendNotification
33
     */
34 1
    public function send($notifiable, Notification $notification)
35
    {
36 1
        if (! $url = $notifiable->routeNotificationFor('hangoutsChat')) {
37
            return;
38
        }
39
40 1
        $webhookData = $notification->{'toHangoutsChat'}($notifiable)->toArray();
41
42 1
        $response = $this->client->post($url, [
43 1
            'query' => Arr::get($webhookData, 'query'),
44 1
            'body' => json_encode(Arr::get($webhookData, 'data')),
45 1
            'verify' => Arr::get($webhookData, 'verify'),
46 1
            'headers' => Arr::get($webhookData, 'headers'),
47
        ]);
48
49 1
        if ($response->getStatusCode() >= 300 || $response->getStatusCode() < 200) {
50 1
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
51
        }
52
53
        return $response;
54
    }
55
}
56