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

sirn-se / websocket-php / 8346487915

19 Mar 2024 04:15PM UTC coverage: 22.584% (-77.4%) from 100.0%
8346487915

push

github

sirn-se
Temp test verification

2 of 2 new or added lines in 1 file covered. (100.0%)

742 existing lines in 32 files now uncovered.

222 of 983 relevant lines covered (22.58%)

0.23 hits per line

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

0.0
/src/Message/Message.php
1
<?php
2

3
/**
4
 * Copyright (C) 2014-2024 Textalk and contributors.
5
 * This file is part of Websocket PHP and is free software under the ISC License.
6
 */
7

8
namespace WebSocket\Message;
9

10
use DateTimeImmutable;
11
use DateTimeInterface;
12
use Stringable;
13
use WebSocket\Frame\Frame;
14
use WebSocket\Trait\StringableTrait;
15

16
/**
17
 * WebSocket\Message\Message class.
18
 * Abstract superclass for WebSocket messages.
19
 */
20
abstract class Message implements Stringable
21
{
22
    use StringableTrait;
23

24
    protected $opcode;
25
    protected $content;
26
    protected $timestamp;
27

28
    public function __construct(string $content = '')
29
    {
UNCOV
30
        $this->content = $content;
×
UNCOV
31
        $this->timestamp = new DateTimeImmutable();
×
32
    }
33

34
    public function getOpcode(): string
35
    {
UNCOV
36
        return $this->opcode;
×
37
    }
38

39
    public function getLength(): int
40
    {
UNCOV
41
        return strlen($this->content);
×
42
    }
43

44
    public function getTimestamp(): DateTimeInterface
45
    {
UNCOV
46
        return $this->timestamp;
×
47
    }
48

49
    public function getContent(): string
50
    {
UNCOV
51
        return $this->content;
×
52
    }
53

54
    public function setContent(string $content = ''): void
55
    {
UNCOV
56
        $this->content = $content;
×
57
    }
58

59
    public function hasContent(): bool
60
    {
UNCOV
61
        return $this->content != '';
×
62
    }
63

64
    public function getPayload(): string
65
    {
UNCOV
66
        return $this->content;
×
67
    }
68

69
    public function setPayload(string $payload = ''): void
70
    {
UNCOV
71
        $this->content = $payload;
×
72
    }
73

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

© 2026 Coveralls, Inc