Code Duplication    Length = 30-30 lines in 2 locations

src/Clients/WSClient.php 1 location

@@ 12-41 (lines=30) @@
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

tests/Clients/WSClientTest.php 1 location

@@ 12-41 (lines=30) @@
9
 * Class WSClientTest
10
 * @package Cobak78\RancherApi\Clients
11
 */
12
class WSClientTest
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