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

sirn-se / websocket-php / 5610959835

pending completion
5610959835

push

github

Sören Jensen
Middleware support

14 of 14 new or added lines in 4 files covered. (100.0%)

283 of 676 relevant lines covered (41.86%)

1.66 hits per line

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

0.0
/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;
×
24
        parent::__construct($content);
×
25
    }
26

27
    public function getCloseStatus(): ?int
28
    {
29
        return $this->status;
×
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);
×
40
        $status_str = '';
×
41
        foreach (str_split($status_binstr, 8) as $binstr) {
×
42
            $status_str .= chr(bindec($binstr));
×
43
        }
44
        return $status_str . $this->content;
×
45
    }
46

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