ChatTopic::onSubscribe()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 2
1
<?php
2
3
namespace Eole\Websocket\Topic;
4
5
use Ratchet\Wamp\WampConnection;
6
use Eole\Sandstone\Websocket\Topic;
7
8
class ChatTopic extends Topic
9
{
10
    /**
11
     * {@InheritDoc}
12
     */
13
    public function onSubscribe(WampConnection $conn, $topic)
14
    {
15
        parent::onSubscribe($conn, $topic);
16
17
        $this->broadcast([
18
            'type' => 'join',
19
            'player' => $conn->user,
20
        ]);
21
    }
22
23
    /**
24
     * {@InheritDoc}
25
     */
26
    public function onPublish(WampConnection $conn, $topic, $event)
27
    {
28
        $this->broadcast([
29
            'type' => 'message',
30
            'player' => $conn->user,
31
            'message' => $event,
32
        ]);
33
    }
34
35
    /**
36
     * {@InheritDoc}
37
     */
38
    public function onUnSubscribe(WampConnection $conn, $topic)
39
    {
40
        $this->broadcast([
41
            'type' => 'leave',
42
            'player' => $conn->user,
43
        ]);
44
45
        parent::onUnSubscribe($conn, $topic);
46
    }
47
}
48