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

sirn-se / websocket-php / 7071466687

02 Dec 2023 04:59PM UTC coverage: 99.659%. First build
7071466687

push

github

sirn-se
Http middleware, cleanup

37 of 40 new or added lines in 5 files covered. (92.5%)

876 of 879 relevant lines covered (99.66%)

20.88 hits per line

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

88.24
/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\{
14
    LoggerAwareInterface,
15
    LoggerAwareTrait
16
};
17
use Stringable;
18
use WebSocket\Connection;
19
use WebSocket\Http\{
20
    HttpHandler,
21
    Message as HttpMessage
22
};
23
use WebSocket\Message\Message;
24

25
/**
26
 * WebSocket\Middleware\Callback class.
27
 * Generic middleware using callbacks.
28
 */
29
class Callback implements
30
    LoggerAwareInterface,
31
    ProcessHttpIncomingInterface,
32
    ProcessHttpOutgoingInterface,
33
    ProcessIncomingInterface,
34
    ProcessOutgoingInterface,
35
    Stringable
36
{
37
    use LoggerAwareTrait;
38

39
    private $incoming;
40
    private $outgoing;
41
    private $httpIncoming;
42
    private $httpOutgoing;
43

44
    public function __construct(
45
        Closure|null $incoming = null,
46
        Closure|null $outgoing = null,
47
        Closure|null $httpIncoming = null,
48
        Closure|null $httpOutgoing = null,
49
    ) {
50
        $this->incoming = $incoming;
8✔
51
        $this->outgoing = $outgoing;
8✔
52
        $this->httpIncoming = $httpIncoming;
8✔
53
        $this->httpOutgoing = $httpOutgoing;
8✔
54
    }
55

56
    public function processIncoming(ProcessStack $stack, Connection $connection): Message
57
    {
58
        if (is_callable($this->incoming)) {
2✔
59
            return call_user_func($this->incoming, $stack, $connection);
2✔
60
        }
61
        return $stack->handleIncoming();
1✔
62
    }
63

64
    public function processOutgoing(ProcessStack $stack, Connection $connection, Message $message): Message
65
    {
66
        if (is_callable($this->outgoing)) {
2✔
67
            return call_user_func($this->outgoing, $stack, $connection, $message);
2✔
68
        }
69
        return $stack->handleOutgoing($message);
1✔
70
    }
71

72
    public function processHttpIncoming(ProcessHttpStack $stack, Connection $connection): HttpMessage
73
    {
74
        if (is_callable($this->httpIncoming)) {
1✔
NEW
75
            return call_user_func($this->httpIncoming, $stack, $connection);
×
76
        }
77
        return $stack->handleIncoming();
1✔
78
    }
79

80
    public function processHttpOutgoing(
81
        ProcessHttpStack $stack,
82
        Connection $connection,
83
        HttpMessage $message
84
    ): HttpMessage {
85
        if (is_callable($this->httpOutgoing)) {
1✔
NEW
86
            return call_user_func($this->httpOutgoing, $stack, $connection, $message);
×
87
        }
88
        return $stack->handleOutgoing($message);
1✔
89
    }
90

91
    public function __toString(): string
92
    {
93
        return get_class($this);
7✔
94
    }
95
}
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