BroadcastNotificationCreated   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 2

Test Coverage

Coverage 35.7%

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 2
cbo 2
dl 0
loc 75
ccs 5
cts 14
cp 0.357
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A broadcastOn() 0 4 1
A channelName() 0 6 1
A broadcastWith() 0 7 1
1
<?php
2
3
namespace Illuminate\Notifications\Events;
4
5
use Illuminate\Queue\SerializesModels;
6
use Illuminate\Notifications\Notification;
7
use Illuminate\Broadcasting\PrivateChannel;
8
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
9
10
class BroadcastNotificationCreated implements ShouldBroadcast
11
{
12
    use SerializesModels;
13
14
    /**
15
     * The notifiable entity who received the notification.
16
     *
17
     * @var mixed
18
     */
19
    public $notifiable;
20
21
    /**
22
     * The notification instance.
23
     *
24
     * @var \Illuminate\Notifications\Notification
25
     */
26
    public $notification;
27
28
    /**
29
     * The notification data.
30
     *
31
     * @var array
32
     */
33
    public $data = [];
34
35
    /**
36
     * Create a new event instance.
37
     *
38
     * @param  mixed  $notifiable
39
     * @param  \Illuminate\Notifications\Notification  $notification
40
     * @param  array  $data
41
     * @return void
0 ignored issues
show
Comprehensibility Best Practice introduced by
Adding a @return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.

Adding a @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

Please refer to the PHP core documentation on constructors.

Loading history...
42
     */
43 1
    public function __construct($notifiable, $notification, $data)
44
    {
45 1
        $this->data = $data;
46 1
        $this->notifiable = $notifiable;
47 1
        $this->notification = $notification;
48 1
    }
49
50
    /**
51
     * Get the channels the event should broadcast on.
52
     *
53
     * @return array
54
     */
55
    public function broadcastOn()
56
    {
57
        return [new PrivateChannel($this->channelName())];
58
    }
59
60
    /**
61
     * Get the data that should be sent with the broadcasted event.
62
     *
63
     * @return array
64
     */
65
    public function broadcastWith()
66
    {
67
        return array_merge($this->data, [
68
            'id' => $this->notification->id,
69
            'type' => get_class($this->notification),
70
        ]);
71
    }
72
73
    /**
74
     * Get the broadcast channel name for the event.
75
     *
76
     * @return string
77
     */
78
    protected function channelName()
79
    {
80
        $class = str_replace('\\', '.', get_class($this->notifiable));
81
82
        return $class.'.'.$this->notifiable->getKey();
83
    }
84
}
85