• 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

80.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;
10✔
28
        $this->timestamp = new DateTime();
10✔
29
    }
30

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

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

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

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

51
    public function setContent(string $content = ''): void
52
    {
53
        $this->content = $content;
×
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);
1✔
64
    }
65

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

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

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