PushmixChannel   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 35
ccs 11
cts 11
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A send() 0 16 3
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