• 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/Middleware/PingInterval.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\Middleware;
9

10
use Psr\Log\{
11
    LoggerAwareInterface,
12
    LoggerAwareTrait
13
};
14
use Stringable;
15
use WebSocket\Connection;
16
use WebSocket\Message\{
17
    Ping,
18
    Message
19
};
20
use WebSocket\Trait\StringableTrait;
21

22
/**
23
 * WebSocket\Middleware\PingInterval class.
24
 * Handles close procedure.
25
 */
26
class PingInterval implements LoggerAwareInterface, ProcessOutgoingInterface, ProcessTickInterface, Stringable
27
{
28
    use LoggerAwareTrait;
29
    use StringableTrait;
30

31
    private $interval;
32

33
    public function __construct(int|null $interval = null)
34
    {
UNCOV
35
        $this->interval = $interval;
×
36
    }
37

38
    public function processOutgoing(ProcessStack $stack, Connection $connection, Message $message): Message
39
    {
UNCOV
40
        $this->setNext($connection); // Update timestamp for next ping
×
UNCOV
41
        return $stack->handleOutgoing($message);
×
42
    }
43

44
    public function processTick(ProcessTickStack $stack, Connection $connection): void
45
    {
46
        // Push if time exceeds timestamp for next ping
UNCOV
47
        if ($connection->isWritable() && time() >= $this->getNext($connection)) {
×
UNCOV
48
            $this->logger->debug("[ping-interval] Auto-pushing ping");
×
UNCOV
49
            $connection->send(new Ping());
×
UNCOV
50
            $this->setNext($connection); // Update timestamp for next ping
×
51
        }
UNCOV
52
        $stack->handleTick();
×
53
    }
54

55
    private function getNext(Connection $connection): int
56
    {
UNCOV
57
        return $connection->getMeta('pingInterval.next') ?? $this->setNext($connection);
×
58
    }
59

60
    private function setNext(Connection $connection): int
61
    {
UNCOV
62
        $next = time() + ($this->interval ?? $connection->getTimeout());
×
UNCOV
63
        $connection->setMeta('pingInterval.next', $next);
×
UNCOV
64
        return $next;
×
65
    }
66
}
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