NotificationEvent   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 9
c 1
b 0
f 0
dl 0
loc 43
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A broadcastOn() 0 3 1
A broadcastWith() 0 4 1
1
<?php
2
3
namespace App\Events;
4
5
use Illuminate\Broadcasting\Channel;
6
use Illuminate\Broadcasting\InteractsWithSockets;
7
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
8
use Illuminate\Queue\SerializesModels;
9
10
/**
11
 * Class NotificationEvent
12
 *
13
 * Use sockets to broadcast notification to user.
14
 *
15
 * @package App\Events
16
 */
17
class NotificationEvent extends Event implements ShouldBroadcast
18
{
19
    use InteractsWithSockets, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by App\Events\NotificationEvent: $id, $relations, $class, $connection, $keyBy
Loading history...
20
21
    /** @var array */
22
    private $data;
23
24
    /** @var int */
25
    private $userId;
26
27
    /**
28
     * NotificationEvent constructor.
29
     *
30
     * Initialize notification data and user that should receive the notification.
31
     *
32
     * @param  array  $data
33
     * @param $userId
34
     */
35
    public function __construct(array $data, $userId)
36
    {
37
        $this->data   = $data;
38
        $this->userId = $userId;
39
    }
40
41
    /**
42
     * Get the channels the notification should broadcast on.
43
     *
44
     * @return Channel|Channel[]
45
     */
46
    public function broadcastOn()
47
    {
48
        return new Channel('user.' . $this->userId);
49
    }
50
51
    /**
52
     * Notification data
53
     *
54
     * @return array
55
     */
56
    public function broadcastWith()
57
    {
58
        return [
59
            'notification' => $this->data
60
        ];
61
    }
62
}
63