WSClient   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A socketConnect() 0 21 1
1
<?php
2
3
namespace Cobak78\RancherApi\Clients;
4
5
use Ratchet\Client\WebSocket;
6
use Ratchet\RFC6455\Messaging\Message;
7
8
/**
9
 * Class WSClient
10
 * @package Cobak78\RancherApi\Clients
11
 */
12
class WSClient
13
{
14
15
    /**
16
     * @param string $wsUrl
17
     * @param string $token
18
     */
19
    public function socketConnect(string $wsUrl, string $token)
20
    {
21
        /** @var $conn WebSocket */
22
        \Ratchet\Client\connect($wsUrl . '?token=' . $token)
23
            ->then(function($conn) {
24
25
                /** @var $msg Message */
26
                $conn->on('message', function($msg) use ($conn) {
27
28
                    $msg = base64_decode($msg->getPayload());
29
30
                    echo "Received: {$msg}\n";
31
32
                    $conn->close();
33
                });
34
35
            }, function ($e) {
36
37
                echo "Could not connect: {$e->getMessage()}\n";
38
            });
39
    }
40
41
}
42