• 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

33.33
/src/Middleware/Callback.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 Closure;
13
use Psr\Log\LoggerAwareInterface;
14
use Psr\Log\LoggerAwareTrait;
15
use WebSocket\Connection;
16
use WebSocket\Message\Message;
17

18
/**
19
 * WebSocket\Middleware\Callback class.
20
 * Generic middleware using callbacks.
21
 */
22
class Callback implements LoggerAwareInterface, ProcessIncomingInterface, ProcessOutgoingInterface
23
{
24
    use LoggerAwareTrait;
25

26
    private $incoming;
27
    private $outgoing;
28

29
    public function __construct(?Closure $incoming = null, ?Closure $outgoing = null)
30
    {
31
        $this->incoming = $incoming;
1✔
32
        $this->outgoing = $outgoing;
1✔
33
    }
34

35
    public function processIncoming(ProcessStack $stack, Connection $connection): Message
36
    {
37
        if (is_callable($this->incoming)) {
×
38
            return call_user_func($this->incoming, $stack, $connection);
×
39
        }
40
        return $stack->handleIncoming();
×
41
    }
42

43
    public function processOutgoing(ProcessStack $stack, Connection $connection, Message $message): Message
44
    {
45
        if (is_callable($this->outgoing)) {
×
46
            return call_user_func($this->outgoing, $stack, $connection, $message);
×
47
        }
48
        return $stack->handleOutgoing($message);
×
49
    }
50

51
    public function __toString(): string
52
    {
53
        return get_class($this);
1✔
54
    }
55
}
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