• 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

90.0
/src/Message/Message.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
use DateTime;
13
use WebSocket\Frame\Frame;
14

15
/**
16
 * WebSocket\Message\Message class.
17
 * Abstract superclass for WebSocket messages.
18
 */
19
abstract class Message
20
{
21
    protected $opcode;
22
    protected $content;
23
    protected $timestamp;
24

25
    public function __construct(string $content = '')
26
    {
27
        $this->content = $content;
5✔
28
        $this->timestamp = new DateTime();
5✔
29
    }
30

31
    public function getOpcode(): string
32
    {
33
        return $this->opcode;
5✔
34
    }
35

36
    public function getLength(): int
37
    {
38
        return strlen($this->content);
5✔
39
    }
40

41
    public function getTimestamp(): DateTime
42
    {
43
        return $this->timestamp;
×
44
    }
45

46
    public function getContent(): string
47
    {
48
        return $this->content;
3✔
49
    }
50

51
    public function setContent(string $content = ''): void
52
    {
53
        $this->content = $content;
2✔
54
    }
55

56
    public function hasContent(): bool
57
    {
58
        return $this->content != '';
×
59
    }
60

61
    public function __toString(): string
62
    {
63
        return get_class($this);
5✔
64
    }
65

66
    public function getPayload(): string
67
    {
68
        return $this->content;
2✔
69
    }
70

71
    public function setPayload(string $payload = ''): void
72
    {
73
        $this->content = $payload;
2✔
74
    }
75

76
    // Split messages into frames
77
    public function getFrames(int $framesize = 4096): array
78
    {
79
        $frames = [];
4✔
80
        $split = str_split($this->getPayload(), $framesize) ?: [''];
4✔
81
        foreach ($split as $i => $payload) {
4✔
82
            $frames[] = new Frame(
4✔
83
                $i === 0 ? $this->opcode : 'continuation',
4✔
84
                $payload,
4✔
85
                $i === array_key_last($split)
4✔
86
            );
4✔
87
        }
88
        return $frames;
4✔
89
    }
90
}
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