• 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/CloseHandler.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
    Close,
18
    Message
19
};
20
use WebSocket\Trait\StringableTrait;
21

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

31
    public function processIncoming(ProcessStack $stack, Connection $connection): Message
32
    {
UNCOV
33
        $message = $stack->handleIncoming(); // Proceed before logic
×
UNCOV
34
        if (!$message instanceof Close) {
×
UNCOV
35
            return $message;
×
36
        }
UNCOV
37
        if ($connection->isWritable()) {
×
38
            // Remote sent Close; acknowledge and close for further reading
UNCOV
39
            $this->logger->debug("[close-handler] Received 'close', status: {$message->getCloseStatus()}");
×
UNCOV
40
            $ack =  "Close acknowledged: {$message->getCloseStatus()}";
×
UNCOV
41
            $connection->closeRead();
×
UNCOV
42
            $connection->send(new Close($message->getCloseStatus(), $ack));
×
43
        } else {
44
            // Remote sent Close/Ack: disconnect
UNCOV
45
            $this->logger->debug("[close-handler] Received 'close' acknowledge, disconnecting");
×
UNCOV
46
            $connection->disconnect();
×
47
        }
UNCOV
48
        return $message;
×
49
    }
50

51
    public function processOutgoing(ProcessStack $stack, Connection $connection, Message $message): Message
52
    {
UNCOV
53
        $message = $stack->handleOutgoing($message); // Proceed before logic
×
UNCOV
54
        if (!$message instanceof Close) {
×
UNCOV
55
            return $message;
×
56
        }
UNCOV
57
        if ($connection->isReadable()) {
×
58
            // Local sent Close: close for further writing, expect remote acknowledge
UNCOV
59
            $this->logger->debug("[close-handler] Sent 'close', status: {$message->getCloseStatus()}");
×
UNCOV
60
            $connection->closeWrite();
×
61
        } else {
62
            // Local sent Close/Ack: disconnect
UNCOV
63
            $this->logger->debug("[close-handler] Sent 'close' acknowledge, disconnecting");
×
UNCOV
64
            $connection->disconnect();
×
65
        }
UNCOV
66
        return $message;
×
67
    }
68
}
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