Completed
Pull Request — master (#447)
by Marcel
02:47 queued 01:22
created

HealthHandler   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A onOpen() 0 10 1
A onMessage() 0 4 1
A onClose() 0 4 1
A onError() 0 4 1
1
<?php
2
3
namespace BeyondCode\LaravelWebSockets\Server;
4
5
use Exception;
6
use GuzzleHttp\Psr7\Response;
7
use Psr\Http\Message\RequestInterface;
8
use Ratchet\ConnectionInterface;
9
use Ratchet\Http\HttpServerInterface;
10
11
class HealthHandler implements HttpServerInterface
12
{
13
    /**
14
     * Handle the socket opening.
15
     *
16
     * @param  \Ratchet\ConnectionInterface  $connection
17
     * @param  \Psr\Http\Message\RequestInterface  $request
18
     * @return void
19
     */
20
    public function onOpen(ConnectionInterface $connection, RequestInterface $request = null)
21
    {
22
        $response = new Response(
23
            200,
24
            ['Content-Type' => 'application/json'],
25
            json_encode(['ok' => true])
26
        );
27
28
        tap($connection)->send(\GuzzleHttp\Psr7\str($response))->close();
29
    }
30
31
    /**
32
     * Handle the incoming message.
33
     *
34
     * @param  \Ratchet\ConnectionInterface  $connection
35
     * @param  string  $message
36
     * @return void
37
     */
38
    public function onMessage(ConnectionInterface $connection, $message)
39
    {
40
        //
41
    }
42
43
    /**
44
     * Handle the websocket close.
45
     *
46
     * @param  \Ratchet\ConnectionInterface  $connection
47
     * @return void
48
     */
49
    public function onClose(ConnectionInterface $connection)
50
    {
51
        //
52
    }
53
54
    /**
55
     * Handle the websocket errors.
56
     *
57
     * @param  \Ratchet\ConnectionInterface  $connection
58
     * @param  WebSocketException  $exception
59
     * @return void
60
     */
61
    public function onError(ConnectionInterface $connection, Exception $exception)
62
    {
63
        //
64
    }
65
}
66