UserPresent   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 50
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A broadcastWith() 0 5 1
A broadcastAs() 0 3 1
A broadcastOn() 0 3 1
A __construct() 0 4 1
1
<?php
2
3
namespace FaithGen\SDK\Events\Commenter;
4
5
use FaithGen\SDK\Models\User;
6
use Illuminate\Broadcasting\InteractsWithSockets;
7
use Illuminate\Broadcasting\PrivateChannel;
8
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
9
use Illuminate\Foundation\Events\Dispatchable;
10
use Illuminate\Queue\SerializesModels;
11
12
class UserPresent implements ShouldBroadcastNow
13
{
14
    use Dispatchable, InteractsWithSockets, SerializesModels;
0 ignored issues
show
introduced by
The trait Illuminate\Queue\SerializesModels requires some properties which are not provided by FaithGen\SDK\Events\Commenter\UserPresent: $id, $relations, $class, $connection, $keyBy
Loading history...
15
    /**
16
     * @var array
17
     */
18
    private array $data;
19
    /**
20
     * @var User
21
     */
22
    private User $user;
23
24
    /**
25
     * Create a new event instance.
26
     *
27
     * @param  User  $user
28
     * @param  array  $data
29
     */
30
    public function __construct(User $user, array $data)
31
    {
32
        $this->data = $data;
33
        $this->user = $user;
34
    }
35
36
    /**
37
     * Get the channels the event should broadcast on.
38
     *
39
     * @return \Illuminate\Broadcasting\Channel|array
40
     */
41
    public function broadcastOn()
42
    {
43
        return new PrivateChannel('comments-'.$this->data['category'].'-'.$this->data['item_id']);
44
    }
45
46
    public function broadcastWith()
47
    {
48
        return [
49
            'user'      => $this->user,
50
            'coming_in' => (bool) $this->data['presence'],
51
        ];
52
    }
53
54
    /**
55
     * Broadcast event name.
56
     *
57
     * @return string
58
     */
59
    public function broadcastAs()
60
    {
61
        return 'user.joined';
62
    }
63
}
64