• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

sirn-se / websocket-php / 5557224007

pending completion
5557224007

push

github

sirn-se
Close messages

57 of 57 new or added lines in 6 files covered. (100.0%)

605 of 607 relevant lines covered (99.67%)

23.24 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

94.12
/src/Message/Close.php
1
<?php
2

3
/**
4
 * Copyright (C) 2014-2023 Textalk and contributors.
5
 *
6
 * This file is part of Websocket PHP and is free software under the ISC License.
7
 * License text: https://raw.githubusercontent.com/sirn-se/websocket-php/master/COPYING.md
8
 */
9

10
namespace WebSocket\Message;
11

12
/**
13
 * WebSocket\Message\Close class.
14
 * A Close WebSocket message.
15
 */
16
class Close extends Message
17
{
18
    protected $opcode = 'close';
19
    protected $status = 0;
20

21
    public function __construct(int $status = 0, string $content = '')
22
    {
23
        $this->status = $status;
14✔
24
        parent::__construct($content);
14✔
25
    }
26

27
    public function getCloseStatus(): int
28
    {
29
        return $this->status;
13✔
30
    }
31

32
    public function setCloseStatus(int $status): void
33
    {
34
        $this->status = $status;
1✔
35
    }
36

37
    public function getPayload(): string
38
    {
39
        if (!$this->status) {
13✔
40
            return $this->content;
×
41
        }
42
        $status_binstr = sprintf('%016b', $this->status);
13✔
43
        $status_str = '';
13✔
44
        foreach (str_split($status_binstr, 8) as $binstr) {
13✔
45
            $status_str .= chr(bindec($binstr));
13✔
46
        }
47
        return $status_str . $this->content;
13✔
48
    }
49

50
    public function setPayload(string $payload = ''): void
51
    {
52
        $this->status = 0;
13✔
53
        $this->content = '';
13✔
54
        if (strlen($payload) > 0) {
13✔
55
            $this->status = current(unpack('n', $payload));
12✔
56
        }
57
        if (strlen($payload) > 2) {
13✔
58
            $this->content = substr($payload, 2);
12✔
59
        }
60
    }
61
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc