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

sirn-se / websocket-php / 5608975860

pending completion
5608975860

push

github

Sören Jensen
Middleware support

90 of 90 new or added lines in 8 files covered. (100.0%)

245 of 671 relevant lines covered (36.51%)

1.27 hits per line

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

93.33
/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 = null;
20

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

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

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

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

47
    public function setPayload(string $payload = ''): void
48
    {
49
        $this->status = 0;
2✔
50
        $this->content = '';
2✔
51
        if (strlen($payload) > 0) {
2✔
52
            $this->status = current(unpack('n', $payload));
2✔
53
        }
54
        if (strlen($payload) > 2) {
2✔
55
            $this->content = substr($payload, 2);
2✔
56
        }
57
    }
58
}
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