Test Setup Failed
Push — develop ( e0b6c5...2b0ae3 )
by Jaime
04:53 queued 02:15
created

WSClientTest::socketConnect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 9

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
cc 1
eloc 9
nc 1
nop 2
1
<?php
2
3
namespace Cobak78\RancherApi\Clients;
4
5
use Ratchet\Client\WebSocket;
6
use Ratchet\RFC6455\Messaging\Message;
7
8
/**
9
 * Class WSClientTest
10
 * @package Cobak78\RancherApi\Clients
11
 */
12 View Code Duplication
class WSClientTest
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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