Passed
Push — master ( f0b67b...ec9c11 )
by y
01:29
created

MessageHandler::setBinaryStream()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 3
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace Helix\Socket\WebSocket;
4
5
class MessageHandler {
6
7
    /**
8
     * @var WebSocketClient
9
     */
10
    protected $client;
11
12
    /**
13
     * @param WebSocketClient $client
14
     */
15
    public function __construct (WebSocketClient $client) {
16
        $this->client = $client;
17
    }
18
19
    /**
20
     * @param string $binary
21
     */
22
    public function onBinary (string $binary): void {
23
        unset($binary);
24
        throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle binary data.");
25
    }
26
27
    /**
28
     * @param string $text
29
     */
30
    public function onText (string $text): void {
31
        $this->onText_CheckUtf8($text);
32
        throw new WebSocketError(Frame::CLOSE_UNHANDLED_DATA, "I don't handle text.");
33
    }
34
35
    /**
36
     * Throws if the payload isn't UTF-8.
37
     *
38
     * @param string $text
39
     */
40
    protected function onText_CheckUtf8 (string $text): void {
41
        if (!mb_detect_encoding($text, 'UTF-8', true)) {
42
            throw new WebSocketError(Frame::CLOSE_BAD_DATA, "Received TEXT is not UTF-8.");
43
        }
44
    }
45
46
}