Passed
Push — master ( e5b31a...cf340d )
by Arthur
04:48
created

WebNotificationChannel::send()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 7
nc 2
nop 2
dl 0
loc 14
ccs 0
cts 11
cp 0
crap 12
rs 10
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: arthur
5
 * Date: 14.10.18
6
 * Time: 21:39
7
 */
8
9
namespace Foundation\Channels;
10
11
12
use Foundation\Events\WebNotificationCreatedEvent;
13
use Illuminate\Notifications\Channels\BroadcastChannel;
14
use Illuminate\Notifications\Notification;
15
use Illuminate\Notifications\Messages\BroadcastMessage;
16
17
class WebNotificationChannel extends BroadcastChannel
18
{
19
    /**
20
     * Send the given notification.
21
     *
22
     * @param  mixed  $notifiable
23
     * @param  \Illuminate\Notifications\Notification  $notification
24
     * @return array|null
25
     */
26
    public function send($notifiable, Notification $notification)
27
    {
28
        $message = $this->getData($notifiable, $notification);
29
30
        $event = new WebNotificationCreatedEvent(
31
            $notifiable, $notification, is_array($message) ? $message : $message->data
32
        );
33
34
        if ($message instanceof BroadcastMessage) {
35
            $event->onConnection($message->connection)
36
                ->onQueue($message->queue);
37
        }
38
39
        return $this->events->dispatch($event);
40
    }
41
}
42