• 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

83.33
/src/Middleware/ProcessStack.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\Middleware;
11

12
use WebSocket\Connection;
13
use WebSocket\Message\Message;
14

15
/**
16
 * WebSocket\Middleware\ProcessStack class.
17
 * Worker stack for middleware implementations.
18
 */
19
class ProcessStack
20
{
21
    private $connection;
22
    private $processors;
23
    private $cb;
24

25
    public function __construct(Connection $connection, array $processors, $cb)
26
    {
27
        $this->connection = $connection;
10✔
28
        $this->processors = $processors;
10✔
29
        $this->cb = $cb;
10✔
30
    }
31

32
    public function handleIncoming(): Message
33
    {
34
        $processor = array_shift($this->processors);
2✔
35
        if ($processor) {
2✔
36
            return $processor->processIncoming($this, $this->connection);
×
37
        }
38
        return call_user_func($this->cb);
2✔
39
    }
40

41
    public function handleOutgoing(Message $message): Message
42
    {
43
        $processor = array_shift($this->processors);
9✔
44
        if ($processor) {
9✔
45
            return $processor->processOutgoing($this, $this->connection, $message);
×
46
        }
47
        call_user_func($this->cb, $message);
9✔
48
        return $message;
1✔
49
    }
50
}
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