PushmixChannel::send()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 8
c 1
b 0
f 0
nc 3
nop 2
dl 0
loc 16
ccs 8
cts 8
cp 1
crap 3
rs 10
1
<?php
2
3
namespace Pushmix\WebNotification;
4
5
use GuzzleHttp\Exception\RequestException;
6
use Illuminate\Notifications\Notification;
7
use Pushmix\WebNotification\Exceptions\CouldNotSendNotification;
8
9
class PushmixChannel
10
{
11
    /** @var PushmixClient */
12
    protected $pusmixClient;
13
14 3
    public function __construct(PushmixClient $pusmixClient)
15
    {
16 3
        $this->pusmixClient = $pusmixClient;
17 3
    }
18
19
    /**
20
     * Send Notification.
21
     *
22
     * @param mixed $notifiable
23
     * @param \Illuminate\Notifications\Notification $notification
24
     *
25
     * @return \Psr\Http\Message\ResponseInterface
26
     * @throws \Pushmix\WebNotification\Exceptions\CouldNotSendNotification
27
     */
28 3
    public function send($notifiable, Notification $notification)
29
    {
30 3
        if (! $to = $notifiable->routeNotificationFor('Pushmix')) {
31 1
            return;
32
        }
33
34 2
        $parameters = $notification->/* @scrutinizer ignore-call */toPushmix($to)->toArray();
35
36
        // initialize subscription key and api url
37 2
        $this->pusmixClient->initKey()->initApiUrl();
38
39
        // Call with parameters
40
        try {
41 2
            return $this->pusmixClient->sendNotification($parameters);
42 1
        } catch (RequestException $e) {
43 1
            throw CouldNotSendNotification::error($e);
44
        }
45
    }
46
47
    /***/
48
}
49